zoukankan      html  css  js  c++  java
  • angular 常用指令和方法

    方法

    angular.copy()

    angular.extend(dst,src)  //把src的所有属性复制到dst

    var debug = true,
        Logger = {
            print: function(s) {
                return debug ? s : ‘’ 
           }
        };
    
    app.controller(‘ControllerOne’, [ ‘$scope’, function($scope) {
        // mixin $scope
        angular.extend($scope, Logger);
        // define our $scope
        angular.extend($scope, {
            myVar: 1,
            log: function() { this.print(this.myVar); }
        });
    }]);
    
    app.controller(‘ControllerTwo’, [ ‘$scope’, function($scope) {
        // mixin $scope
        angular.extend($scope, Logger);
        // define our $scope
        angular.extend($scope, {
            myVar: 2,
            log: function() { this.print(this.myVar); }
        });
    }]);
    app.controller(‘ThingController’, [ ‘$scope’, function($scope) {
        // private
        var _thingOne = ‘one’,
            _thingTwo = ‘two’;
    
        // models
        angular.extend($scope, {
            get thingOne() {
            return _thingOne;
            },
            set thingOne(value) {
               if (value !== ‘one’ && value !== ‘two’) {
                 throw new Error(‘Invalid value (‘+value+‘) for thingOne’);
            },
            get thingTwo() {
            return _thingTwo;
            },
            set thingTwo(value) {
               if (value !== ‘two’ && value !== ‘three’) {
                 throw new Error(‘Invalid value (‘+value+‘) for thingTwo’);
            }
       });
    
        // methods
        angular.extend($scope, {
           // in HTML template, something like {{ things }}
           get things() { 
                return _thingOne + ‘ ‘ + _thingTwo; 
            }
        });
    }]);

    指令

    ng-cinclude  //绑定模板  

    $sce.trustAsHtml

    ng-bind-html  //绑定html

    app.filter('to_trusted', ['$sce', function ($sce) {
      return function (text) {
          return $sce.trustAsHtml(text);
      };
    }]);
    
    <p ng-bind-html="currentWork.description | to_trusted"></p>
    var ngBindHtmlDirective = ['$sce', function($sce) {
      return function(scope, element, attr) {
        scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) {
          element.html(value || '');
        });
      };
    }];

    url:https://docs.angularjs.org/api/ng/service/$sce

    服务

    $injector

    //IOC容器, $injector.get("serviceName"),$injector.get("$rootScope")

    $animate.leave(element)

    $httpProvider //可以改变$http 的默认行为

    $route //会监视$location.url(),会是在map在route 中定义的url

     

  • 相关阅读:
    内存区间poj 1840
    旋转实现iOS(iPhone/iPad) 屏幕旋转响应函数的缺点与窗口大小位置调整,以及解决办法
    文件模式JAVASE16IO流_3
    配置修改postgresql streaming replication
    查看字段postgresql pg_buffercache
    窗体方法VB.NET设置控件和窗体的显示级别
    流量最小HDU 3491 最小割
    方法返回javascript学习实录 之二(数组操作等等utils) 刘啸尘
    配置路由器静态路由配置
    任务问题Oracle 技术支持之现场优化的思维路径
  • 原文地址:https://www.cnblogs.com/yfann/p/4602126.html
Copyright © 2011-2022 走看看