Angular指令观察模板div的变化

时间:2016-01-18 15:32:30

标签: angularjs

我有以下指令:

.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}} _ dropDown div中的任何更改。我该怎么办?

1 个答案:

答案 0 :(得分:1)

您只需在链接功能中创建$ 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;
        }
}