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);
        });
        
    }]);
  • 相关阅读:
    Delphi 中多线程同步的一些处理方法
    delphi 讲的比较详细的多线程
    Delphi MSComm 实时串口通讯
    Delphi多线程数据库查询(ADO)
    常用学习链接收藏
    Linux目录及常用命令
    DEBUG和INFO的使用
    git命令
    9.9 接口与工厂
    9.4 Java中的多继承
  • 原文地址:https://www.cnblogs.com/toodeep/p/4988527.html
Copyright © 2011-2022 走看看