I'm trying to run this example about routing, which uses AngularJS v1.0.7
. But I want to make it work using AngularJS v1.3.3
我正在尝试运行这个使用AngularJS v1.0.7的路由示例。但我希望使用AngularJS v1.3.3使其工作
Everything in my example works but the ng-view
part. So I'm not sure whether the problem is the ng-view
or the routing
itself.
我的示例中的所有内容都可以运行,但是ng-view部分。所以我不确定问题是ng-view还是路由本身。
As the tutorial suggests, I tried 3 ways of calling ng-view
. But none seems to work.
正如教程所示,我尝试了三种调用ng-view的方法。但似乎都没有效果。
You can define ng-view in main html file in one of the below way.
您可以使用以下方法之一在主html文件中定义ng-view。
<div ng-view=""></div> <ng-view></ng-view> <div class="ng-view"></div>
How should I make it work in AngularJS v1.3.3
?
我应该如何在AngularJS v1.3.3中使它工作?
2 个解决方案
#1
Older versions of angular included routing in the core.
较旧版本的角度包含在核心中的路由。
To use it now you have to include angular-route.js
or angular-route.min.js
also and inject ngRoute
as a module dependency.
现在使用它你必须包括angular-route.js或angular-route.min.js并注入ngRoute作为模块依赖项。
var sampleApp = angular.module('sampleApp', ['ngRoute']);
原始示例已升级
#2
After angular 1.2 you need to depend your module on ngRoute
在角度1.2之后,您需要将模块依赖于ngRoute
var sampleApp = angular.module('sampleApp', ['ngRoute']);
If you click on the error in your Dev Console, you'll see this at the middle of the page:
如果您单击Dev Console中的错误,您将在页面中间看到:
In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x or later, be sure that you've installed ngRoute.
在AngularJS 1.2.0及更高版本中,ngRoute已移至其自己的模块。如果在升级到1.2.x或更高版本后出现此错误,请确保已安装ngRoute。
#1
Older versions of angular included routing in the core.
较旧版本的角度包含在核心中的路由。
To use it now you have to include angular-route.js
or angular-route.min.js
also and inject ngRoute
as a module dependency.
现在使用它你必须包括angular-route.js或angular-route.min.js并注入ngRoute作为模块依赖项。
var sampleApp = angular.module('sampleApp', ['ngRoute']);
原始示例已升级
#2
After angular 1.2 you need to depend your module on ngRoute
在角度1.2之后,您需要将模块依赖于ngRoute
var sampleApp = angular.module('sampleApp', ['ngRoute']);
If you click on the error in your Dev Console, you'll see this at the middle of the page:
如果您单击Dev Console中的错误,您将在页面中间看到:
In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x or later, be sure that you've installed ngRoute.
在AngularJS 1.2.0及更高版本中,ngRoute已移至其自己的模块。如果在升级到1.2.x或更高版本后出现此错误,请确保已安装ngRoute。