角度指令观察模板 div 的变化



我有以下指令:

.directive('cmplt', function ($parse, $http, $sce, $timeout) {
  return {
     restrict: 'EA',
     template: '<div><input id='{{id}}_fieldInpt' /></div id='{{id}}_dropDown'><div></div>'
     link: function($scope, elem, attrs) {
         //code here
     }
  }

我想做的是观察/观察 {{id}}_dropDowndiv 中的任何变化。我该怎么做?

您只需

要在链接函数中创建$scope。

.directive('angucomplete', function ($parse, $http, $sce, $timeout) {
    return {
        restrict: 'EA',
        template: '<div><input id='{{id}}_fieldInpt' /></div   id='{{id}}_dropDown'><div></div>'
        link: function($scope, elem, attrs) {
            $scope.id = 123;
        }
}

最新更新