1

I use the alert directive like this:

<alert ng-repeat="alert in alerts" type="'danger'">{{alert}}</alert>

where alerts is something like: ['Hello', 'World'].

I would like to create an alerts directive which will be used like this:

<alerts model="alerts"></alerts>

which will be equivalent to the above.

I tried to start with: (live demo)

app.directive('alerts', function() {
  return {
    restrict: 'E',
    scope: {
      model: '='
    },
    template: '<alert ng-repeat="alert in {{model}}" type="\'danger\'"></alert>'
  };
});

but I get the following error:

Syntax Error: Token 'model' is unexpected, expecting [:] at column 3 of the expression [{{model}}] starting at [model}}].

Why is that?

What would be the right way to implement the alerts directive?

1 Answer 1

4

Remove {{ and }} from the ng-repeat binding in the template. It would work. You do not need to use {{ }} inside an expression.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.