0

I know that this issue has been mentioned before. Although I believe that this issue is slightly different.

Link Link

I have the following code

<textarea name="Text2" cols="40" rows="2" ng-model="pageModel.storeText" ng-pattern="/^(?:\d+(?:, *|))*\d+$/" class="form-control"></textarea>
<span ng-show="itemStoreForm.Text2.$error.pattern">ERROR</span>

I need the ng-show in the span to initiate a function I have based in a controller:

$scope.storeError = function(){

    messageService.setMessage("messageContainer", "Please enter store numbers in correct format", "danger");
};

How can I call the function storeError()?

Community
  • 1
  • 1
Anton Hughes
  • 1,845
  • 4
  • 21
  • 32

1 Answers1

2

If you can access the scope-object from your controller, try

$scope.$watch('itemStoreForm.Text2.$error', function(error) {
    if (error && error.pattern) {
        $scope.storeError();
    }
});

Since the FormController is published on $scope via name, it should be accessible for a watch-function.

ivarni
  • 17,658
  • 17
  • 76
  • 92