realtebo
realtebo

Reputation: 25691

AngularJs: Error compiling a ng-switch

Code

<input type="text" ng-model="person.name" />
<div ng-switch on="person.name"></div>
<p ng-switch-default>And the winner is</p>
<h1 ng-switch-when="Ari">{{ person.name }}</h1>

what's wrong? I got Error: [$compile:ctreq] , but removing these 4 lines all goes ok.

I got this example on 'ng-book' (a very BAD book)

Upvotes: 0

Views: 103

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191779

ng-switch element needs to wrap the ng-switch-on and ng-switch-default directives (the latter ones require the former).

<input type="text" ng-model="person.name" />
<div ng-switch on="person.name">
    <p ng-switch-default>And the winner is</p>
    <h1 ng-switch-when="Ari">{{ person.name }}</h1>
</div>

http://jsfiddle.net/7DJSd/

Upvotes: 1

Related Questions