Angularjs restrict 용도

Posted by Albert 2827Day 14Hour 28Min 50Sec ago [2017-07-24]

주요하게 restrict 는 4가지로 사용할수있다. (A,E,C,M)

A:

=====================================

app.directive("setOnClick", function($compile){

  return {

    restrict: "A",

    link: function(scope, elm, attrs, ctrl)

    {

      elm.attr("ng-click", "clickMe()");

      elm.removeAttr("set-on-click")

      $compile(elm)(scope);

    }

  };

});


E:

============================

app.directive('abt', function() {

  return {

    restrict: "E",

    replace: true,

    template: "<div>It's albert site</div>"

  }

});


usage: <abt></abt>

C: 

app.directive("testClass", function() {

    return {

        restrict : "C",

        template : "<p>Directive class</p>"

    };

});

<div class="testClass"></div>


M: 

==============================

app.directive("ngClass", function() {

    return {

        restrict : "M",

        replace : true,

        template : "<h1>comment</h1>"

    };

});

<!-- directive: w3-test-directive -->





LIST

Copyright © 2014 visionboy.me All Right Reserved.