Skip to content

Commit 3e9ce80

Browse files
authored
Create README.md
1 parent 0eb8c08 commit 3e9ce80

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,4 +1174,51 @@ app.controller('pageMain2Ctrl', function($scope, $state) {
11741174
}
11751175
})
11761176
```
1177+
**ng路由**
1178+
1.加载ng路由模块,引入angular.js之后
11771179
1180+
```html
1181+
<script type="text/javascript" src="../js/angular.js"></script>
1182+
<script type="text/javascript" src="../js/angular-route.js"></script>
1183+
```
1184+
1185+
2.包含了 ngRoute 模块作为主应用模块的依赖模块
1186+
```javascript
1187+
angular.module('helloWscatsApp',['ngRoute'])
1188+
```
1189+
1190+
3.使用`ngView`指令
1191+
```javascript
1192+
<div ng-view></div>
1193+
```
1194+
1195+
**$routeProvider**
1196+
两个核心方法`when()``otherwise()`
1197+
|||
1198+
|-|-|
1199+
|controller|function或string类型。在当前模板上执行的controller函数,生成新的scope|
1200+
|controllerAs|string类型,为controller指定别名|
1201+
|template|string或function类型,视图所用的模板,这部分内容将被ngView引用|
1202+
|templateUrl|string或function类型,当视图模板为单独的html文件或是使用了`<script type="text/ng-template">`定义模板时使用|
1203+
|resolve|指定当前controller所依赖的其他模块|
1204+
|redirectTo|重定向的地址|
1205+
1206+
可以使用`$routeProvider`用来定义路由规则
1207+
```javascript
1208+
module.config(['$routeProvider', function($routeProvider) {
1209+
$routeProvider
1210+
.when('/', {
1211+
template: '他是Oaoafly'
1212+
})
1213+
.when('/wscats', {
1214+
template: '他是Wscats'
1215+
})
1216+
.when('/windiest', {
1217+
template: '她是Windiest'
1218+
})
1219+
.otherwise({
1220+
redirectTo: '/'
1221+
});
1222+
}]);
1223+
```
1224+
```

0 commit comments

Comments
 (0)