Want to set an iframe src attribute from a variable in AngularJS? I suspect looking at the excerpt that the function trustSrc from trustSrc(currentProject.url) is not defined in the controller.
You need to inject the $sce service in the controller and trustAsResourceUrl the url there.
In the controller:
1 2 3 4 5 6 7 | function AppCtrl($scope, $sce) { // ... $scope.setProject = function (id) { $scope.currentProject = $scope.projects[id]; $scope.currentProjectUrl = $sce.trustAsResourceUrl($scope.currentProject.url); } } |
In the template:
1 | <iframe ng-src="{{currentProjectUrl}}"> <!--content--> </iframe> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.