Reputation: 643
Can anyone tell me how to pass a constant value to html in AngularJS? Example: In html file, I have an ng-if condition.
<span ng-if="prod.ID">10</span>
Here I want to make the value "10" as configurable. Something like :
<span ng-if="prod.ID == constants.prodID">10</span>
Any suggestions?
Thank You in advance.
Upvotes: 0
Views: 5766
Reputation: 658
First, create a constant:
app.constant("ProductConst", {
"prodTotal": 10
});
Second, inject it into your controller
app.controller('MyController', function ($scope, ProductConst) {
$scope.productTotal = ProductConst.prodTotal;
}
Last, use it in your view:
<span ng-if="prod.ID > productTotal "></span>
Upvotes: 4
Reputation: 2249
$scope
That should do the trick :-)
Upvotes: 3