简体   繁体   English

AngularJS 路由问题 ui-router

[英]AngularJS routing issue ui-router

I'am not getting what is the problem, I have an index.html file and an app.js file我没有得到什么问题,我有一个 index.html 文件和一个 app.js 文件

  1. Index.html contains two ui-sref inside anchor tag Index.html 在锚标签内包含两个 ui-sref
  2. app.js as stateprovider. app.js 作为状态提供者。 Please solve the issue.请解决问题。 Thanks for taking out your precious time感谢您抽出宝贵的时间

 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>

If you:如果你:

  • keep only one script for angular router(version 1.0 is the latest) angular路由器只保留一个脚本(1.0版本是最新的)

  • replace $stateprovider with $stateProvider$stateprovider替换 $ $stateProvider

it works fine:它工作正常:

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM