码迷,mamicode.com
首页 > 其他好文 > 详细

angular 常用指令和方法

时间:2015-06-26 14:47:46      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

ng-bind-html  //绑定html

ng-cinclude  //绑定模板

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; 
        }
    });
}]);

 

angular 常用指令和方法

标签:

原文地址:http://www.cnblogs.com/yfann/p/4602126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!