I'm trying to do some data manipulation using a one-way binding in my custom directive, but I receive "undefined" first time. What should I do with directive and not to use $watch ?
Example:
<one val={{arr[1].value}}> </one>
<two val="arr[0].value"> </two>
Directives:
.directive('one', function(){
return {
restrict: 'E',
scope: {
val:'@'
},
template: '<div> 1111 {{val}} </div>' ,
link: function (scope) {
console.log('scope', scope.val) // SHOWS UNDEFINED BUT INSERT DATA IN TEMPLATE
if(scope.val) scope.val = scope.val.replace(/\d/g,'')
}
}
})
.directive('two', function(){
return {
restrict: 'E',
scope: {
val:'='
},
template: '<div> 2222 {{val}} </div>' ,
link: function (scope) {
console.log('scope', scope.val)
scope.val = scope.val.replace(/\d/g,'')
}
}
});
Example: JsFiddle