[英]How to check $window variable in ng-if or ng-show
我声明了一个变量var variable1,我需要使用ng-if或ng-show检查所有页面中的变量
one of the ways is to attach the variable to the $rootScope
. 其中一种方法是将变量附加到$rootScope
。 For example: 例如:
var app = angular.module('app', []); ... app.run(function($rootScope){ $rootScope.myspecialvar = "hello"; }); ... //can be used in js app.controller(function($rootScope){ console.log($rootScope.myspecialvar); });
<!-- can be used in html --> {{myspecialvar}} <!-- or --> <div ng-if='myspecialvar'></div>
Read here about $rootScope
: How do I use $rootScope in Angular to store variables? 在这里阅读关于$rootScope
: 如何在Angular中使用$ rootScope来存储变量?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.