ngMessages with Angular 1.5.x Component

Viewed 1233

I just tried introducing ngMessages into my app that's using Components that were added in 1.5. As soon as I include any reference to ngMessage in my template I'm receiving this error message:

Error: $compile:ctreq Missing Required Controller.

This is a common error with ngMessages and the normal remedy is suggested here: https://docs.angularjs.org/error/$compile/ctreq?p0=ngMessages&p1=ngMessage

However, I'm using components, which are a special type of directive and this doesn't appear to be an option for components.

Has anyone gotten ngMessages to work within a component in 1.5?

The syntax for use with a directive is like this:

myApp.directive('myDirective', function() {
  return {
    require: 'ngModel',
    ...
  }
}

The component documentation: https://docs.angularjs.org/guide/component doesn't cover an equivalent to require.

2 Answers

It happens when you don't have correct div structure. First div has to include ng-messages, and one inside should be ng-message. From Documentation:

<ANY **ng-messages**="expression" role="alert">
    <ANY **ng-message**="stringValue">...</ANY>
</ANY>

Angular's debug message is unhelpful in this instance and cause more confusion.

Related