angular 상용 지령 및 방법

5568 단어 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)

좋은 웹페이지 즐겨찾기