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);
        });
        
    }]);
  • 相关阅读:
    flutter 3des
    flutter踩坑记
    【OS_Windows】彻底关闭windows10自动更新
    使用 httpclient 上传下载文件
    git操作
    jmeter在Windows下请求https的接口
    python xlsxwriter简单使用
    asp.net core webapi 文件下载实现
    使用微信小程序连接到 MQTT 云服务
    MQTT.js 入门教程
  • 原文地址:https://www.cnblogs.com/toodeep/p/4988527.html
Copyright © 2011-2022 走看看