Answer the question
In order to leave comments, you need to log in
AngularJs shows undefined in scope directive, how to avoid?
I make an http request in the parent controller
app.controller("playerController", function (
$scope,
$rootScope,
$http,
) {
const ctrl = this;
ctrl.globalState = $rootScope.state;
$http({
method: "GET",
url: "https://api.deezer.com/artist/338/top?limit=30",
}).then((response) => {
ctrl.globalState.songsData = response.data.data;
});
});
<div class="list-group">
<list data='ctrl.globalState.songsData'></list>
</div>
app.directive("list", function () {
return {
replace: true,
scope: {
data: "=",
},
templateUrl: "directives/list/list.html",
controllerAs: "ctrl",
controller: function ($scope, $rootScope, $playerService) {
const ctrl = this;
console.log($scope.data); // undefined
},
};
})
<list data='[1,2,3]'></list>
- everything is fine, it outputs to the console in the scope, but when I make a request and send the data, it comes-undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question