I have a pageheader
template above angularjs's ui-view. I want to specify a variable showDropdown
to control the appearence of some DOMs in pageheader
. The showDropdown
variable is specific with the ui-view
. For example showDropdown
is true
in the first view, and false
in the second view. How can I make it change according to ui-view?
I've tried to set the variable in the onEnter()
of stateProvider
, but has no influence.
HTML,
<pageheader></pageheader>
<br />
<div class="container">
<div class="row"><div class="col-xs-12 no-padding"><div ui-view="view"></div></div></div>
</div>
pageherder template,
<div>
......
</div>
<div ng-if="showDropdown">
........
</div>
JS,
.config(function($stateProvider)
{
$stateProvider
.state('printer',
{
url: "/printer",
views:
{
"view":
{
templateUrl: "/static/tpls/cloud/app/printer.php"
}
},
onEnter: function(){
showDropdown = false;
}
})
.state('control',
{
url: "/control",
views:
{
"view":
{
templateUrl: "/static/tpls/cloud/app/control.php"
}
}
})
})
Edit for Pengyy's answer
app.controller('CloudController', ['$scope', '$http', '$interval', '$timeout', 'optSev', '$state', '$rootScope', function($scope, $http, $interval, $timeout, optSev, $state, $rootScope)
{
var search = window.location.search.substring(1);
var paras = search.split("&");
paras = paras[0].split("=");
pid = paras[1];
$scope.pid = pid;
$scope.active = {};
$scope.idle = true;
$scope.active.status = {};
$scope.active.state = {};
$scope.showDropdown = $state.current.showDropdown;
//$scope.showDropdown = $rootScope.showDropdown;
//console.log($scope.showDropdown);
console.log($state);
console.log($state.current);
//console.log($state.$current);
.....
It's very weried,
console.log($state); // it shows the showDropdown
console.log($state.current); // the showDropdown is missed.