I want to use ng-bind directive instead of brackets {{ }} in AngularJS. We have example:
<tag type="{{value1}}">{{value2}}</tag>
Change value2 is easy. We have:
<tag type="{{value1}}" ng-bind="value2"></tag>
How can we change {{value1}} to remove brackets notation?
The first solution by DonJuwe does not working correct for me. Maybe I am doing something wrong. For example in HTML:
<div ng-controller="TestController">
1. <p style="{{style}}">{{style}}</p>
2. <p style="getStyle()" ng-bind="style"></p>
3. <p style="getStyle()" ng-bind="getStyle()"></p>
<input type="button" ng-click="setStyle()" value="Change Style" />
</div>
in controller:
var module = angular.module('myApp', []);
module.controller('TestController', function ($scope) {
$scope.style = 'color: rgb(0, 0, 0)';
$scope.getStyle = function() {
return $scope.style;
};
$scope.setStyle = function() {
$scope.style = 'color: rgb('+Math.floor(Math.random() * 255)+', 0, 0)';
}
});
After click on button, all texts (1., 2., 3.) are correct but only line 1 changing color to random red.