您的位置:首页 > Web前端 > AngularJS

angularJS 路由配置

2018-03-01 16:36 302 查看
$routeProvider.when(url, {
    template: string,
    templateUrl: string,
    controller: string, function 或 array,
    controllerAs: string,
    redirectTo: string, function,
    resolve: object<key, function>
});
参数说明:
①template:
如果我们只需要在ng-view中插入简单的HTML内容,则使用该参数:
.when('/computers',{template:'这是电脑分类页面'})
②templateUrl:
如果我们需要在ng-view中插入HTML模板文件,则使用该参数:
$routeProvider.when('/computers', {
    templateUrl: 'views/computers.html',

});

以上代码会从服务端获取 views/computers.html 文件内容插入到 ng-view 中。
③controller:
function、string或数组类型,在当前模板上执行的controller函数,生成新的scope。
④controllerAs:
string类型,为controller指定别名。
⑤redirectTo:
重定向的地址。
⑥resolve:
指定当前controller所依赖的其他模块。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: