我试过在这里查看其他$ rootScope:infdig问题,找不到真正向我解释的问题,或者我理解的问题.与AngularJs文档相同.我希望有人能帮帮忙.
我在$ scope上创建了一个函数,它接受一个参数并调用api GET请求并返回一个带有just和"id"和"name"的json对象.然后,此函数将对象的名称返回给调用它的指令.
该函数从指令调用,但一旦它执行,它就会陷入每秒一百个"rootScope:infdig"的错误中.该指令也从不呈现返回的"名称"的文本.我知道http调用有效,因为我在控制台中记录了"名称".
这是我的控制器:
owlyfm.controller('landingPageController', [ "$scope", "$log", "$http", "$location", "apiUrlsService", function ($scope, $log, $http, $location, apiUrlsService) {
$http.get("https://api.backand.com:443/1/objects/Albums?pageSize=3&pageNumber=1&deep=true&relatedObjects=true")
.success( function(result){
$scope.featuredAlbums = result.data;
//$log.info($scope.featuredAlbums);
})
.error( function(data, status){
$log.error(data);
});
$scope.getAlbumArtist = function(artistId){
$http.get("https://api.backand.com:443/1/objects/Artists/" + artistId)
.success(function(result){
var artistsName = result.name;
$log.info(artistsName);
return artistsName;
});
}
}]);
Run Code Online (Sandbox Code Playgroud)
这是我创建指令的地方:
owlyfm.directive("featuredAlbum", function(){
return{
restrict: 'E',
templateUrl: 'directives/featuredAlbum.html',
scope: {
albumObject: "=",
getAlbumArtistFunction: "&"
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我在视图中调用指令的地方
<div class="row fluid-container" >
<featured-album ng-repeat="featuredAlbum in featuredAlbums" album-object="featuredAlbum" get-album-artist-function="getAlbumArtist(album)" …Run Code Online (Sandbox Code Playgroud)