I declared one variable var variable1 and i need to check variable in all pages using ng-if or ng-show
Asked
Active
Viewed 931 times
1 Answers
0
one of the ways is to attach the variable to the $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?