2

I declared one variable var variable1 and i need to check variable in all pages using ng-if or ng-show

yole
  • 92,896
  • 20
  • 260
  • 197

1 Answers1

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?

Community
  • 1
  • 1
Yerken
  • 1,944
  • 1
  • 14
  • 18