jQuery find() method not working in AngularJS directive

前端 未结 7 1007
说谎
说谎 2021-01-31 14:26

I am having trouble with angularjs directives finding child DOM elements with the injected angular element.

For example I have a directive like so:



        
7条回答
  •  囚心锁ツ
    2021-01-31 15:30

    You can do it like this:

     var myApp = angular.module('myApp', [])
      .controller('Ctrl', ['$scope', function($scope) {
         $scope.aaa = 3432
     }])
     .directive('test', function () {
        return {
           link: function (scope, elm, attr) {
               var look = elm.children('#findme').addClass("addedclass");
               console.log(look);
            }
       };
    });
    
    
    TEST Div
    {{aaa}}

    http://jsfiddle.net/FZGKA/133/

提交回复
热议问题