Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMessagesInclude processed after parent ngMessages is removed from DOM #12695

Closed
@awerlang

Description

@awerlang

As the title says, ngMessagesInclude processed after parent ngMessages is removed from DOM. It fails because angular can't find parent controller for linking inner messages. It doesn't happen when ngMessage's are inlined inside the ngMessages element, or while parent element is still present on DOM.

Have an ng-messages like this:

<div ng-if="myForm.$submitted" ng-messages="myForm.myName.$error">
  <div ng-messages-include="messages.html"></div>
</div>

Submission is triggered by:

this.change = function(myForm) {
  var self = this;
  myForm.$setSubmitted();    // event A
  $scope.$applyAsync(function () {
    self.currentStep = 'step2.html';     // event B
  });
};

At event (A), messages.html is downloaded. Because it uses $templateRequest, linking is stalled until server returns. Meanwhile, event (B) proceeds with the removal of ngMessages and its children from DOM. Later, ngMessagesInclude content arrives and angular will compile it. But at that point there's no way to retrieve ngMessages controller anymore.

Plnkr: http://plnkr.co/edit/0GOOLERvfj7n9vDVEyZp?p=preview

Most of the time, it will happen together with an ngIf condition.

Tested against version 1.4.4.

I've found a way to avoid that:

ng-if="myForm.$submitted && myForm.myName.$invalid" 

To solve that at component side, the require: '^^ngMessages' could be made optional and check that condition during linking.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions