zoukankan      html  css  js  c++  java
  • ngRoute插件

    angular中可以使用插件,例如ngRoute插件就是用与路由控制。

    首先要在模块中引入即可:

    var m1 = angular.module('myApp',['ngRoute']);

    然后我们进行供应商配置

    m1.config(['$routeProvider',function($routeProvider){
        
        $routeProvider
            .when('/aaa/:num',{
                template : '<p>首页的内容</p>{{name}}',
                controller : 'Aaa'
            })
            .when('/bbb',{
                template : '<p>学员的内容</p>{{name}}',
                controller : 'Bbb'
            })
            .when('/ccc',{
                template : '<p>课程的内容</p>{{name}}',
                controller : 'Ccc'
            })
            .otherwise({
                redirectTo : '/aaa'
            });
        
    }]);

    如上,通过when方法来制定不同的hash值对应不同的视图,hash只后面还可以带上参数num,

    如何改变hash值?

    1.可以通过a链接的href属性

    2.通过$location.path()方法来改变

    m1.controller('Aaa',['$scope','$location','$routeParams',function($scope,$location,$routeParams){
        
        $scope.name = 'hello';
        $scope.$location = $location;
        
        console.log( $routeParams );
        
    }]);

    还可以在run方法中监听路由事件。

    m1.run(['$rootScope',function($rootScope){
        
        $rootScope.$on('$routeChangeStart',function(event,current,pre){
            console.log(event);
            console.log(current);
            console.log(pre);
        });
        
    }]);
  • 相关阅读:
    python字典推导式
    什么是Python 自省
    类变量和实例变量
    Python 使用正则表达式匹配URL网址
    python is 和 “==”的区别
    阮一峰老师的bash教程,建议阅读
    python里的闭包
    什么是生成器
    python访问限制
    pytorch使用Tips
  • 原文地址:https://www.cnblogs.com/toodeep/p/4988527.html
Copyright © 2011-2022 走看看