Angularjs 如何更正ui路由器多命名视图的这种使用
我正在尝试使用angular ui router设置一个没有父模板但包含多个命名视图的页面 有一个简单的html设置:Angularjs 如何更正ui路由器多命名视图的这种使用,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我正在尝试使用angular ui router设置一个没有父模板但包含多个命名视图的页面 有一个简单的html设置: <body> <div ng-app="thing"> <h1>Multiple Views</h1> <div ui-view="oneThing"></div> <div ui-view="twoThing"></div> <div u
<body>
<div ng-app="thing">
<h1>Multiple Views</h1>
<div ui-view="oneThing"></div>
<div ui-view="twoThing"></div>
<div ui-view="threeThing"></div>
<script id="one_thing.html" type="text/ng-template">
<p>one: {{text}}</p>
</script>
<script id="two_thing.html" type="text/ng-template">
<p>two: {{text}}</p>
</script>
<script id="three_thing.html" type="text/ng-template">
<p>three: {{text}}</p>
</script>
</div>
</body>
我认为这意味着总是加载“things”作为路由,并在该状态下加载三个视图,每个视图指向不同的模板和控制器。但我得到的却是一张空白页
我是否误解了它的工作原理或编写方法(或者更糟糕的是,两者都是!!)?默认url是
而不是/
所以$urlRouterProvider.when(“/”,“things”)代码>未被触发
改为
$urlRouterProvider.when(“”,'things')代码>
您的plunkr也可以工作。或者,当然,把$urlRouterProvider.when('''/')代码>啊,啊!我觉得问题出在我的耳朵之间。谢谢你!
'use strict';
var thing = angular.module("thing", ['ui.router']);
thing.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('things', {
url: '/things',
views: {
'oneThing': {
templateUrl:'one_thing.html',
controller: 'oneCtrl'
},
'twoThing': {
templateUrl:'two_thing.html',
controller: 'twoCtrl'
},
'threeThing': {
templateUrl:'three_thing.html',
controller: 'threeCtrl'
}
}
});
$urlRouterProvider.when('/', 'things');
});
thing.controller('oneCtrl', function($scope) {
$scope.text = 'boom';
});
thing.controller('twoCtrl', function($scope) {
$scope.text = 'bang';
});
thing.controller('threeCtrl', function($scope) {
$scope.text = 'wallop';
});