I'm trying to use multiple ng-bind instead of {{}} in a directive, but with no luck.
<my-directive att1="age" att2="22"></my-directive>
angular
.module("app",[])
.directive('myDirective', myDirective);
function myDirective() {
return {
restrict: 'E',
scope: {
att1: '@',
att2: '@'
},
template: '<div class="ng-bind: att1;" ng-bind="att2"></div>'
}
}
No problem in case there's only one ng-bind. In case I have more than one, as in this case, I read somewhere about the notation I'm using "ng-bind: att;" but it's not working.
Also, I wonder if I'd really would need it. Apparently using ng-bind avoid the problem of the double bracket flashing in the screen before the data is loaded, which in this case it's not really important as I'm using the value as a class attribute and thus is not being displayed in the screen. On the other hand it's supposed to be more efficient using ng-bind.
Any ideas? I've seen a couple questions here in stackoverflow regarding this but none of them seem to resolve the matter.
You only can have one
ng-bindper attribute. The value ofng-bindis written as the content of yourdivtag. When you have multipleng-binds they would overwrite each other, so this is not possible.However, if you want to set a class, have a look at the
ngClassdirective here https://docs.angularjs.org/api/ng/directive/ngClass. Your template could look sth like this:This would set the content of
att1into theclass="..."attribute of yourdivand the content ofatt2as the content of yourdiv. The rendered output could beIf you want more than one
ng-bindyou could insert a seperat tag for each ng-bind like this: