Get the argument value of a directive in a controller
I would like to create a directive and use the argument in my controller:
<body ng-app="UssdAuto">
<navigationbar tst="hello">
</navigationbar>
</body>
For this I create a directive and its controller:
navigationBar = {};
navigationBar.directives = {};
navigationBar.controllers = {};
navigationBar.directives.navigationbar = function () {
return {
restrict: 'E',
scope: {
t1: '@tst',
t2: '=tst',
t3: '&tst'
},
templateUrl: "common/navigation_bar/navigation_bar.tpl.html",
controller: "NavigationBarController"
}
};
navigationBar.controllers.NavigationBarController = function ($scope, Api) {
console.log($scope);
console.log($scope.t1);
console.log($scope.t2);
console.log($scope.t3);
};
testApp.directive(navigationBar.directives);
testApp.controller(navigationBar.controllers);
In the console I got this:
Scope {$id: "003", $$childTail: null, $$childHead: null, $$prevSibling:
null, $$nextSibling: null…}
$$asyncQueue: Array[0]
$$childHead: Child
$$childTail: Child
$$destroyed: false
$$isolateBindings: Object
$$listeners: Object
$$nextSibling: Child
$$phase: null
$$prevSibling: null
$$watchers: Array[9]
$id: "003"
$parent: Scope
$root: Scope
nav: Object
t1: "hello"
t2: undefined
t3: function (locals) {
this: Scope
__proto__: Object
and:
undefined navigation_bar.js:33
undefined navigation_bar.js:34
function (locals) {
return parentGet(parentScope, locals);
}
I would like to understand why the console.log($scope.t1); doesn't display
the value as it is in the scope->t1: "hello"
Thank you for your help,
Julio
No comments:
Post a Comment