简体   繁体   中英

Reach a value provider from HTML

How can I reach a value from a module in my HTML? Like module.value("myvalue", true) and in HTML <div ng-show="myvalue">Hello</div> .

Edit

OK, one solution was to change the value to an object instead of a primitive, like this: module.value("myvalue", {value: true}) and <div ng-show="myvalue.value">Hello</div> and then include in the controller $scope.myvalue = myvalue and inject myvalue in the argument list of the controller.

If myvalue is a primitive type, then you should use a constant:

module.constant('myvalue', true);

myvalue is then injectable:

module.controller('controller', function(myvalue) {
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM