angular度路线不工作 – 一些模板url错误
我开始与AngularJS,但路由器不工作在我的网站上。
这是一些configuration与我的路线有关:
首先,app.js:
// Declare app level module which depends on views, and components angular.module('myApp', [ 'ngRoute', 'myApp.view1' ]). config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) { $locationProvider.hashPrefix('!'); $routeProvider.otherwise({redirectTo: '/'}); }]);
其次,view1.js
angular.module('myApp.view1', ['ngRoute']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/view1', { templateUrl: '/views/view1/view1.html', controller: 'View1Ctrl' }); }]) .controller('View1Ctrl', [function() { }]);
angular.js,app.js和view1.js被添加到index.html
ng-view用于显示view1.html中的内容
这是我的文件夹树:
项目
**pipe理员
****** app.js
****** index.html
******的意见
********** view1
*************** view1.html
*************** view1.js
你能给我一些build议,使其工作?
感谢您收看我的问题!
我build议将你的configuration全部移到一个config
。 也没有必要在你的模块实例化中引用myApp。 另一件事是确保你的index.html中有angularjs路由文件。 以下将工作。
尝试这个:
var app = angular.module('myApp', ['ngRoute']). app.config(function($locationProvider, $routeProvider) { $locationProvider.hashPrefix('!'); $routeProvider.when('/view1', { templateUrl: '/views/view1/view1.html', controller: 'View1Ctrl' }) .otherwise({redirectTo: '/'}); });