Saturday, 15 March 2014

javascript - When should prefer angular directive over html native tag? -



javascript - When should prefer angular directive over html native tag? -

i'm big fan of angularjs, started lately utilize in of 'coding fun' projects. have big curiosity:

i have 2 inputs, 1 disabled ng-disabled directive , other disabled html tag (a improve illustration in link):

//... <input type="text" disabled value="this html input text disabled" /> <input type="text" ng-disabled="true" value="disabled angular js directive" /> //...

using browser ability can right click on input , remove disabled , ng-disabled tags 1 disabled tag editable, other 1 still tracked angular when ng-disabled directives has been removed.

so, when , why should prefer using ng directives on native html tags? impact of letting angular track these actions? worth utilize everywhere?

use native html 'disabled' if element should disabled. (static, illustration if want provide input text , never allow user alter it) utilize angular if should alter based on variables value in scope.

for example, button should alter state of input.

<input type="button" ng-click="inpdisabled = true" >disable input</input> <input type="text" ng-disabled="inpdisabled" />

live example

no harm come if still utilize ng-disabled="true" it's redundant.

javascript html angularjs angularjs-directive

No comments:

Post a Comment