微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AngularJS路由

1、AngularJS路由

        允许我们通过不同的URL访问不同的内容,可以实现多视图的单页WEB应用。

URL的形式为http://runoob.com/first/page,但在单页Web应用中AngularJS痛过#!+标记实现,例如:

http://runoob.com/#!/first http://runoob.com/#!/second http://runoob.com/#!/third

2、路由设置对象

       可以通过不同的模板来实现;

      template:需要在ng-view中插入简单的HTML内容,则使用该参数;

     templateUrl:需要在ng-view中插入HTML模板文件,则使用该参数;

     controller:function、string或数组类型,在当前模板上执行的controller函数生成新的scope;

     controllerAS:string类型,为controller指定别名;

     redirectTo:重定向的地址;

    resolve::指定当前controller所依赖的其他模块;

$routeProvider.when(url,{
    template:string,//在ng-view中插入简单的html内容
    templateUrl:string,//在ng-view中插入html模版文件
    controller:string,function / array,//在当前模版上执行的controller函数
    controllerAs:string,//为controller指定别名
    redirectTo:string,function,//重定向的地址
    resolve:object<key,function> //指定当前controller所依赖的其他模块
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐