我写了一个简单的演示来尝试理解 ui 路由器。
但问题是,我在使用 ui 路由器时得到了重复的 View 。
这是 stateProvider 部分
app.config(function($stateProvider,$urlRouterProvider){
$urlRouterProvider.otherwise('/baseView');
$stateProvider
.state('baseView',{
url:"/baseView",
templateUrl:"baseView.html"
})
.state('baseView.empty',{
abstract: true,
views:{
"navBar":{
templateUrl:"sideBar.html",
controller: "sideCtrl"
},
"123":{
templateUrl:"content.html"
}
}
})
.state('baseView.empty.content1',{
url:'/content1',
templateUrl:"content1.html"
})
.state('baseView.empty.content2',{
url:'/content2',
templateUrl:"content2.html"
})
})
骗子:http://plnkr.co/edit/Rm0Q50GX2GYvqyKnzkKz?p=preview
当你在plunker中看到预览时你就会发现问题。
我相信问题出在状态提供者部分,因为如果我完全删除状态提供者,就不会重复......
最佳答案
该问题与状态定义无关。原因是您加载了 angular.js 和 ui-router.js 两次,这两次实例化相同的东西。您可以删除其中一个引用以使其正常工作。
关于javascript - 为什么使用 ui-router 时会出现重复的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38932173/