I am a starter in angular js.
I went through similar question How to access parent scope from within a custom directive *with own scope* in AngularJS?
But the answer did not worked for my simple experiment.
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 want my own my-bind
(as replica of ng-bind
)
so value of attribute my-bind
is a name of some scopeVariable and whenever that scope variable value changes, the content of div should get updated with that updated value.
Neither i got the parent scope variable value nor the element get the respective text.
PS : i know i should have used =
but i just starting with @
at least check to find scope variable and use it value.
PS : i also want to avoid using $parent