2013-07-01 2 views
0

<button-large color="green" click="createWorkstation()" busy="disableSave()" busyLabel="Saving...">Save</button-large>Невозможно наблюдать/наблюдать за областью?

Я не могу наблюдать за изменениями на выходе disableSave(). Консоль.log(), показанная в моей директиве, никогда не срабатывает при изменении вывода .busy. Что я делаю не так?

directive('buttonLarge', function() { 
    return { 
     scope: { 
      busy: '&', 
      click: '&' 
     }, 
     replace: true, 
     restrict: 'E', 
     transclude: true, 
     template: '<button class="buttonL" ng-transclude/>', 
     link: function (scope, element, attrs) { 

      //when the button is busy, disable the button 
      if (angular.isDefined(scope.busy())) { 
       scope.$watch(scope.busy(), function() { 
        console.log('watched'); 
       }); 
       attrs.$observe(scope.busy(), function() { 
        console.log('observed'); 
       }); 
      } 

      //setup click event - https://groups.google.com/forum/#!topic/angular/-uVE5WJWwLA 
      if (angular.isDefined(scope.click)) { 
       element.bind('click', scope.click); 
      } 
     } 
    } 
}) 

Контроллер

$scope.newWorkstationDialog = function (workflowProcess) { 
    var d = $dialog. 
     dialog({ 
      resolve: { 
       workflowProcess: function() { 
        return workflowProcess; 
       } 
      } 
     }). 
     open('/partials/admin/'+workflowProcess.entity.slug+'/setup.htm', ['$scope', 'dialog', ..., function ($scope, dialog, ...) { 
      $scope.saving = false; 

      /* Create the workstation */ 
      $scope.createWorkstation = function() { 
       console.log('saving'); 
       $scope.saving = true; 
       $timeout(function() { 
        $scope.saving = false; 
        console.log('stopped saving'); 
       }, 1000); 
      } 

      //Should the save button be disabled? 
      $scope.disableSave = function() { 
       return $scope.saving;//|| $scope.form.$valid; 
      } 

      $scope.cancel = function() { 
       dialog.close(); 
      } 
     }]); 
} 

ответ

2

Ваш синтаксис смотреть в не исправить .Вы следует не использовать рамки, делая часы, потому что внутри него использовать $ парсинга услуги, которые внутренне придают объем. Поэтому вам нужно изменить свой код ниже:

1st option 

scope.$watch(function(){ 
return scope.busy() 
}, function (newvalue,oldvalue) { 
        console.log('watched'); 
       }); 

2nd option 

scope.$watch('busy()', function (newvalue,oldvalue) { 
        console.log('watched'); 
       }); 
+0

Я вижу ... хотя они также не работают. – Webnet

+0

любезно поделиться скрипкой или plunker demo pls –

+0

Для жизни меня я никогда не мог получить работу Angular для работы над JSFiddle ... вот моя попытка: http://jsfiddle.net/Webnet/HkXNc/ – Webnet

Смежные вопросы