I am new to utilizing angular js.
I came across a similar inquiry on How to access parent scope from within a custom directive *with own scope* in AngularJS?
However, the solution provided did not work for my basic test.
Here is the sandbox. http://jsfiddle.net/VJ94U/1364/
angular.module('mod', []).
directive('myBind', function() {
return {
restrict : 'A',
scope : {
scopeVar : '@'
},
link : function(scope,element,attr){
element.attr('ng-bind', scope.scopeVar);
element.text(scope.scopeVar);
}
};
});
var app = angular.module('app', [ 'mod' ]);
angular.element(document).ready(function() {
angular.module('app').run(function($rootScope){
$rootScope.scopeVar = 'This is scope variable.';
});
angular.bootstrap(document, ['app']);
});
I simply need my own my-bind
(similar to ng-bind
)
Therefore, when the value of the attribute my-bind
is the name of a certain scopeVariable, the content within the div should automatically update with the new value of that scope variable.
Unfortunately, I am unable to access the parent scope variable or have the corresponding text displayed within the element.
PS: I understand that I should have used =
, but I am still familiarizing myself with @
. Please verify the ability to locate the scope variable and utilize its value.
PS: I also aim to avoid using $parent