How can an object be passed to a directive in order to access the users
data within the directive's scope
? Despite attempts, I have been unsuccessful. Here is what I've done:
Within my controller, I assigned an array of users
to a scope:
$scope.users = payload.data.results;
Next, I attempted to pass this object to my directive as an attribute:
<display test123='users'></display>
The directive's function:
function ListDisplay() {
var directive = {
replace: 'true',
restrict: 'E',
scope: {
test123: '='
},
controller: ListDisplayController,
controllerAs: 'vm',
bindToController: true,
link: ListDisplayLinkFunc
};
return directive;
function ListDisplayController($scope) {
console.log($scope.test123);
}
function ListDisplayLinkFunc(scope, elem, attr) {
console.log(scope.test123);
}
}
However, when attempting to display scope.data
, it returns undefined.