zoukankan      html  css  js  c++  java
  • angularjs $location 服务

    <!DOCTYPE HTML>
    <html ng-app="myApp">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="angular.min.js"></script>
    <script>
    //对网址信息进行2次的封装。
    
    var m1 = angular.module('myApp',[]);
    m1.controller('Aaa',['$scope','$location',function($scope,$location){
        var a = $location.absUrl();//网址的绝对地址(加的参数进行了编码)
        $location.path('aaa/bbb/ccc').replace();
        $location.hash('hello');
        $location.search({'age':'20'});
        var a = $location.protocol();//地址的协议
        console.log(a);
    }]);
    
    </script>
    </head>
    <body>
    <div ng-controller="Aaa">
    </div>
    </body>
    </html>
    <!DOCTYPE HTML>
    <html ng-app="myApp">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    #parent div{ 300px; height:500px; border:1px #000 solid; margin:20px;}
    #parent ul{ 200px; position:fixed; top:0; right:0;}
    </style>
    <script src="angular.min.js"></script>
    <script>
    
    
    var m1 = angular.module('myApp',[]);
    m1.controller('Aaa',['$scope','$location','$anchorScroll',function($scope,$location,$anchorScroll){
        $scope.change = function(id){
            //console.log(id);
            $location.hash(id);
            $anchorScroll();//锚点跳转
        };
    }]);
    
    </script>
    </head>
    
    <body>
    <div id="parent" ng-controller="Aaa">
        <ul>
            <li ng-repeat="id in [1,2,3,4,5]" ng-click="change('div'+id)">{{id}}aaaaaaaaaa</li>
        </ul>
        <div ng-repeat="id in [1,2,3,4,5]" ng-attr-id="div{{id}}">{{id}}</div>
    </div>
    </body>
    </html>
  • 相关阅读:
    【C# 代码小技巧】巧用 linq select 实现遍历集合返回元素 index
    [转载] redis 学习
    Html5 Canvas斗地主游戏
    K-近邻算法(KNN)
    Sql 把Xml字符串转换成一张表
    Asp.Net Mvc4分页,扩展HtmlHelper类
    SQL 分割字符串
    http://q.cnblogs.com/q/54251/
    读强化学习论文之MADDPG
    【回归】记Paddle强化学习训练营
  • 原文地址:https://www.cnblogs.com/yaowen/p/5742154.html
Copyright © 2011-2022 走看看