Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs ngRoute和ui.router对比大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比:

ng-router(angular-router.js) ng-view ngRoute模块 $routeProvider服务 .when() .otherwise();

ui-router(angular-ui-router.js) ui-view ui.router模块 $stateProvider服务 .state(),$urlRouterProvider服务 .otherwise();

ng-router:



    =>
  • >view1
  • >view2
  • <span style="color: #008000">//<span style="color: #008000">js
    angular.module(<span style="color: #800000">'<span style="color: #800000">myApp<span style="color: #800000">',[<span style="color: #800000">'<span style="color: #800000">ngRoute<span style="color: #800000">'<span style="color: #000000">])
    .config([<span style="color: #800000">'<span style="color: #800000">$LOCATIOnProvider<span style="color: #800000">',<span style="color: #800000">'<span style="color: #800000">$routeProvider<span style="color: #800000">'<span style="color: #000000">,function($LOCATIOnProvider,$routeProvider){
    $LOCATIOnProvider.html5Mode(<span style="color: #0000ff">falsE).hashPrefix(<span style="color: #800000">''<span style="color: #000000">);
    $routeProvider
    .when(<span style="color: #800000">'<span style="color: #800000">/view1<span style="color: #800000">'<span style="color: #000000">,{
    templateUrl: <span style="color: #800000">'<span style="color: #800000">view1/view1.html<span style="color: #800000">'<span style="color: #000000">,controller: <span style="color: #800000">'<span style="color: #800000">View1Ctrl<span style="color: #800000">'<span style="color: #000000">
    })
    .when(<span style="color: #800000">'<span style="color: #800000">/view2<span style="color: #800000">'<span style="color: #000000">,{
    templateUrl: <span style="color: #800000">'<span style="color: #800000">view2/view2.html<span style="color: #800000">'<span style="color: #000000">,controller: <span style="color: #800000">'<span style="color: #800000">View2Ctrl<span style="color: #800000">'<span style="color: #000000">
    })
    .otherwise({redirectTo: <span style="color: #800000">'<span style="color: #800000">/view1<span style="color: #800000">'<span style="color: #000000">});
    }])

    大佬总结

    以上是大佬教程为你收集整理的angularjs ngRoute和ui.router对比全部内容,希望文章能够帮你解决angularjs ngRoute和ui.router对比所遇到的程序开发问题。

    如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

    本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
    如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
    标签: