Reputation: 659
I am trying to load dynamic links from the json to into my iframe template. When I load the iframe page, this error pops up. I don't really know why. This is the first time I've seen this error. Here is the code below.
Controller
app.controller('apps', [
'$scope',
'$http',
'contentService',
'gotoService',
'getIndex',
'$routeParams', function($scope, $http, contentService, gotoService, getIndex, $routeParams){
contentService.then(function(data){
$scope.data = data; // access all data
$scope.appsList = $scope.data.appsList; // list of shortcuts
// change url to links
$scope.goTo= function(url){
gotoService.getLink(url);
}
// get index
$scope.getIndex = function(index){
getIndex.current(index);
}
// embed in iframe
$scope.link = function(){
$scope.indexRoute = $routeParams.index;
return $scope.appsList[$scope.indexRoute].url;
}
});
}]);
iframe template
<iframe ng-controller="apps" ng-src="{{link()}}" width="800" height="600">
</iframe>
apps icon template
<div class="apps-background" ng-click="goTo(a.link+'/'+$index); getIndex($index);" ng-style="{'background-image':'url({{a.image}})', 'background-repeat': 'no-repeat', 'background-size': 'cover'}">
Upvotes: 1
Views: 1081
Reputation: 659
I fixed the problem. I changed the code in my controller to this and it worked perfectly.
app.controller('apps', [
'$scope',
'$http',
'contentService',
'gotoService',
'getIndex',
'$routeParams',
'$sce', function($scope, $http, contentService, gotoService, getIndex, $routeParams, $sce){
contentService.then(function(data){
$scope.data = data; // access all data
$scope.data = data; // access all data
$scope.appsList = $scope.data.appsList; // list of shortcuts
// change url to links
$scope.goTo= function(url){
gotoService.getLink(url);
}
// get index
$scope.getIndex = function(index){
getIndex.current(index);
}
// embed in iframe
$scope.link = function(){
$scope.indexRoute = $routeParams.index;
return $sce.trustAsResourceUrl($scope.appsList[$scope.indexRoute].url);
}
});
}]);
Upvotes: 0
Reputation: 136174
You can't have interpolation directive inside a ng-style directive expression, you need to correct it like below.
<div class="apps-background"
ng-click="goTo(a.link+'/'+$index); getIndex($index);"
ng-style="{'background-image': 'url('+ a.image + ')', 'background-repeat': 'no-repeat', 'background-size': 'cover'}">
Upvotes: 1