[英]AngularJS routing issue ui-router
我沒有得到什么問題,我有一個 index.html 文件和一個 app.js 文件
var app=angular.module('myApp',['ui.router']); app.config(function($stateprovider){ var home= { name:'home', url:'/home', template:"<h1>Home</h1>", controller: 'myCtrl' }; var contacts= { name:'contacts', url:'/contacts', template:"<h1>Contacts</h1>", controller: 'myCtrl' }; $stateprovider.state(home) $stateprovider.state(contacts) }); app.controller("myCtrl",function($scope,$http){ })
<:doctype html> <html ng-app="myApp"> <head> <script src="https.//ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min:js"></script> <script src="https.//ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-route:js"></script> <script src="https.//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.20/angular-ui-router:js"></script> <script src="https.//unpkg.com/angular-ui-router@0.4.2/release/angular-ui-router.js"></script> <script src="./app.js"></script> </head> <body > <div ng-controller="myCtrl"> <ul> <li><a ui-sref="home">Home</a></li> <li><a ui-sref="contacts">Contacts</a></li> </ul> <div> <div ui-view> </div> </div> </div> </body> </html>
如果你:
angular路由器只保留一個腳本(1.0版本是最新的)
用$stateprovider
替換 $ $stateProvider
它工作正常:
var app=angular.module('myApp',['ui.router']); app.config(function($stateProvider){ var home= { name:'home', url:'/home', template:"<h1>Home</h1>", controller: 'myCtrl' }; var contacts= { name:'contacts', url:'/contacts', template:"<h1>Contacts</h1>", controller: 'myCtrl' }; $stateProvider.state(home) $stateProvider.state(contacts) }); app.controller("myCtrl",function($scope,$http){ })
<:doctype html> <html ng-app="myApp"> <head> <script src="https.//ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min:js"></script> <script src="https.//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.20/angular-ui-router.js"></script> <script src="./app.js"></script> </head> <body > <div ng-controller="myCtrl"> <ul> <li><a ui-sref="home">Home</a></li> <li><a ui-sref="contacts">Contacts</a></li> </ul> <div> <div ui-view> </div> </div> </div> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.