AngularJS动态路由ngRouteProvider
发布日期:2021-06-29 19:37:04 浏览次数:2 分类:技术文章

本文共 1478 字,大约阅读时间需要 4 分钟。

https://github.com/gonzalo123/ngRouteProvider

router provider for angular js

loading states according to json file

A simple angular application with one state 'home'

angular.module('App', ['ui.router'])    .config(function ($stateProvider, $urlRouterProvider, routerProvider) {        $stateProvider            .state('home', {                url: '/home',                templateUrl: 'templates/home.html'            });        $urlRouterProvider.otherwise('/home');    })    .controller('MainController', function ($scope, router) {        $scope.reload = function() {            router.setUpRoutes();        };    });

We define more states within a json file

{    "xxx": {        "url": "/xxx",        "templateUrl": "templates/xxx.html"    },    "yyy": {        "url": "/yyy",        "templateUrl": "templates/yyy.html"    },    "zzz": {        "url": "/zzz",        "templateUrl": "templates/zzz.html"    }}

and we load them using "Routing"

angular.module('App', ['ui.router', 'Routing'])    .config(function ($stateProvider, $urlRouterProvider, routerProvider) {        $stateProvider            .state('home', {                url: '/home',                templateUrl: 'templates/home.html'            });        $urlRouterProvider.otherwise('/home');        routerProvider.setCollectionUrl('js/routeCollection.json');    })    .controller('MainController', function ($scope, router) {        $scope.reload = function() {            router.setUpRoutes();        };    });

转载地址:https://daqiang.blog.csdn.net/article/details/80332384 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:AngularJs分页组件pagination用法
下一篇:颜色码对照表

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月04日 00时07分04秒