[英]Why wont ngRoute now work and breaks all other Angular functionality?
I am trying to us ngRoute to inject HTML into my web page but it doesn't work. 我正在尝试使用ngRoute将HTML注入到我的网页中,但是它不起作用。
I have the below in my main html document. 我的主要html文件中包含以下内容。
<main ng-view></main>
next i created a folder call views with two HTML files (news.html & sectors.html) 接下来,我创建了一个包含两个HTML文件的文件夹调用视图(news.html和扇区.html)
I have also included angular-route.min.js into my project correctly. 我还正确地将angular-route.min.js包含到我的项目中。 All paths for all files are correct.
所有文件的所有路径均正确。
Next I set up my routes as below, but it renders a blank page and even breaks the rendering of any ng-includes I have implemented which previously worked. 接下来,我按如下所示设置路由,但是它呈现空白页面,甚至破坏了我已经实现的任何ng-includes的呈现,而之前都可以使用。 In addition, it also breaks all other Angular functionality like filtering.
此外,它还会破坏所有其他Angular功能,例如过滤。 There are no errors in the console, it just seems that ngRoute wont work.
控制台中没有错误,只是ngRoute无法正常工作。
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/sectors', {
templateUrl: 'views/sectors.html'
})
.when('/news', {
templateUrl: 'views/news.html',
controller: 'primaryController'
}).otherwise({
redirectTo: '/sectors'
});
}]);
Any help welcome. 任何帮助欢迎。
You can check templateUrl for the path to your html templates. 您可以检查templateUrl以获取html模板的路径。 Everything else seems correct.
其他一切似乎都正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.