angular.js : how to pass ngclick from original dom to directive's dom?

后端 未结 3 1686
情书的邮戳
情书的邮戳 2021-02-04 13:26

Hi there I have this \"confirmable\" button directive which I am working on,

The html code that will trigger the directive \'confirmable\'

      

        
3条回答
  •  清歌不尽
    2021-02-04 13:47

    If you manipulate the DOM in the link stage and want to add angular logic to its element(s) it's required to compile the effected element(s). Let angular inject $compile and invoke it after you have finished processing the DOM and added your ng-* directives.

    function MyDirective($compile)
    {
        return {
            
            restrict: "AE",
            templateUrl: "/path",
            link: (scope, element, attributes) => 
            {
                // Add your directives
    
                $compile(element.contents())(scope);
            }
        };
    }

提交回复
热议问题