I am currently working on injecting the name
from the myController
scope into the myObj
directive as a custom attribute called nameAttr
.
Even though I have set name: '=nameAttr'
in the directive's scope, it doesn't seem to be functioning correctly.
Can someone please point out what mistake I might be making?
https://plnkr.co/edit/qceVMl0w2gv03ZuQVQb8?p=preview
HTML
<my-obj nameAttr="name"></my-obj>
INSIDE THE 'MY-OBJ.HTML'
<h2>{{ name }}</h2>
<ol>
<li ng-repeat="(slug, val) in loop">{{ slug }} - {{ val }}</li>
</ol>
ANGULAR
var mod = angular.module('myApp', []);
mod.controller('myController', myController).directive('myObj', myObject);
function myController($scope){
$scope.name = 'John Smith';
}
function myObject(){
return {
restrict: 'E',
templateUrl: 'my-obj.html',
scope: {
name: '=nameAttr'
},
controller: function($scope){
$scope.loop = {
'one': 'gfshfh',
'two': '32435'
};
}
};
}