我已经在外壳页面(index.html)中初始化了一个属性,我想在通过route.my代码调用的控制器中获取该值。如何获得在外壳页面初始化为控制器的属性值
的index.html:
<html>
//loaded all libraries,modules
<ng-init="status=false"></ng-init>
<ng-init="activator=[{'orders':'active'},{'customers':''},{'about':''}]"></ng-init>
<ul class="nav nav-tabs nav-justified" role="tablist" ng-show="status">
<li class="activator.orders"><a href="#customers">Customers</a></li>
<li class="activator.customers"><a href="#orders">Orders</a></li>
<li class="activator.about"><a href="#about">About</a></li>
</ul>
<ng-view></ng-view>
</html>
orderscontroller.js
app.controller('ordersctrl',function($scope,$rootScope,$http,$cookies,$cookieStore,$location)
{
$rootScope.status="true";
$rootScope.myname=$cookieStore.get('name');
alert($rootScope.activator); //it prints "undefined"
});
个customermanager.js
var app=angular.module('customermanager',['ngRoute','ngCookies','ngAnimate','ui.bootstrap']);
app.config(function($routeProvider)
{
$routeProvider.when('/',
{
controller:'loginctrl',
templateUrl:'views/loginview.html'
})
.when('/orders',
{
controller:'ordersctrl',
templateUrl:'views/ordersview.html'
})
.when('/customers',
{
controller:'customersctrl',
templateUrl:'views/customersview.html'
})
.when('/about',
{
controller:'aboutctrl',
templateUrl:'views/aboutview.html'
})
.otherwise(
{
redirectTo:'/'
});
});
当我点击“#orders”,orderscontroller.js及其相关的看法是called.My要求是通过“激活”属性orderscontroller.js,请帮助。 ..
我使用“角路由”来映射视图和控制器...和我需要得到的属性“激活”是在外壳页面(index.html),我想要在任何控制器中访问该属性我我已经更新了我的代码。希望很明显。 – 2014-10-07 12:32:25
尝试将'ng-init'更改为某个节点的属性。 – 2014-10-07 12:41:35