Javascript ui路由器-ui视图和链接不工作
我正在为angular试用ui路由器。我在我的app.js中将这行代码添加到我的app模块中:Javascript ui路由器-ui视图和链接不工作,javascript,angularjs,Javascript,Angularjs,我正在为angular试用ui路由器。我在我的app.js中将这行代码添加到我的app模块中: angular .module("ngClassifieds", ['ngMaterial', 'ui.router']) .config(function($mdThemingProvider, $stateProvider){ $mdThemingProvider.theme('default') .primaryPalette('teal') .ac
angular
.module("ngClassifieds", ['ngMaterial', 'ui.router'])
.config(function($mdThemingProvider, $stateProvider){
$mdThemingProvider.theme('default')
.primaryPalette('teal')
.accentPalette('orange');
$stateProvider
.state('stateone', {
url:'/stateone',
template: '<h1>State one</h1>'
})
.state('statetwo', {
url: '/statetwo',
template: '<h1>State two</h1>'
});
});
但出于某些原因,它不会在任何链接上加载/显示任何标题,而只是显示没有标题的我的页面
我已经将angular-ui-router.js包含在我的index.html中
如果有人能指出我做错了什么,那就太好了
如果有人想知道:这是我脚本的顺序:
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-animate/angular-animate.js"></script>
<script src="node_modules/angular-aria/angular-aria.js"></script>
<script src="node_modules/angular-material/angular-material.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script src="scripts/app.js"></script>
<script src="components/classifieds.ctr.js"></script>
<script src="components/classifieds.fac.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
由于您没有收到任何错误,因此很难理解出现了什么问题,但您可以查看我的plunkr并找出原因。我去掉了棱角材料
有棱角的
.module(“ngClassifieds”,['ui.router'])
.config(函数($stateProvider){
$stateProvider
.state(“stateone”{
url:“/stateone”,
模板:“状态一”
})
.state('state2'{
url:“/statetwo”,
模板:“状态二”
});
});
你好,普朗克!
index.html上的脚本顺序正确吗?另外,控制台中是否显示任何错误?@AyushBahuguna控制台中没有错误。当我运行localhost:8080/#/stateone链接时,它将更改为:页面将显示,但没有标题。statetwo链接也是如此。您正在使用ui sref作为anchord标记?@digit它不是必需的。他正在显式输入url。@rory-h您能把您的代码放在plunker上吗?这将有助于我们更好地理解。放置所有文件和当前拥有的所有内容。您可能忘记在href中使用“#/”
localhost:8080/#/stateone
localhost:8080/#/statetwo
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-animate/angular-animate.js"></script>
<script src="node_modules/angular-aria/angular-aria.js"></script>
<script src="node_modules/angular-material/angular-material.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script src="scripts/app.js"></script>
<script src="components/classifieds.ctr.js"></script>
<script src="components/classifieds.fac.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script>
angular
.module("ngClassifieds", ['ui.router'])
.config(function( $stateProvider){
$stateProvider
.state('stateone', {
url:'/stateone',
template: '<h1>State one</h1>'
})
.state('statetwo', {
url: '/statetwo',
template: '<h1>State two</h1>'
});
});
</script>
</head>
<body>
<h1>Hello Plunker!</h1>
<a href="#/stateone">Link1</a>
<a href="#/statetwo">Link2</a>
<ui-view></ui-view>
</body>