Generally we use the = to make two-way data binding when creating directives, for example:
app.module('main')
.directive('dirTest'[function(){
return {
scope:{
data:'='
}
}
}])
Then we can use
<dir-test data="xx.data"></dir-test>
To pass the xx.data object to the directive, but it seems that this will make angular watch this expression.
This may be a waste of time once I do not care the change of the data or the data can hardly change.
Which means I need a one-way one-time data passwed to the directive, is this possible?
I ask this question because when I open the Batarang console, I found the regularinterceptedexpression cost too long and watch a lot of watchers. I think the page may run fast if I can remove some unused watchers.
I know there is a one-way from dom to directives by using @, however it seems that it just support string.
In angularjs if you create a directive with scope '@' then it will be Text bindings,which means you will be able to get the value of expression but making changes to it won't reflect back to the html page.so i believe if you create the directive in with scope @ then it will do a job for you.
app.module('main')
.directive('dirTest'[function(){
return {
scope:{
data:'@'
}
}
}]
)
<dir-test data={{xx.data}}></dir-test>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With