0

I am developing an application with Laravel and Angular JS. I am using [[ ]] for data binding.

On binding data in table with ng-switch is getting error and not working.

 <tr ng-repeat="category in categories">
            <td>[[category.Name]]</td>
            <td>[[category.ListOrder]]</td>
            <td ng-switch="category.Status">
              <img ng-switch-when="1" src="{{URL::asset('public/assets/images/icons/ic_active.png')}}"></td>
              <img ng-switch-when="0" src="{{URL::asset('public/assets/images/icons/ic_inactive.png')}}"></td>
            <td>
              <img src="{{URL::asset('public/assets/images/icons/ic_inactive.png')}}">
            </td>
            <td>[[category.updated_at]]</td>
</tr>

The response Status variable getting string values 1 and 0 when I check with Firebug.

How can I solve this....

I am using Angular JS v1.5.8

Error in Console..

 Error: [$compile:ctreq] http://errors.angularjs.org/1.5.8/$compile/ctreq?p0=ngSwitch&p1=ngSwitchWhenN/<@http://localhost/repos/p3-laravel/ppp_admin/public/js/angular.min.js:6:412
Jishad
  • 2,876
  • 8
  • 33
  • 62
  • *"is getting error and not working"* – can you put that in more concrete terms? What's the error message, what is happening, what do you expect to happen instead? – deceze Oct 11 '16 at 12:59
  • @deceze edited question with console error. – Jishad Oct 11 '16 at 13:01
  • @JpDevs can you use the unminified version of AngularJS? it seems you're using the minified version – Technohacker Oct 11 '16 at 13:02
  • @K3v1n Now I check with unminified cdn and now showning error like Error: [$compile:ctreq] Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found! – Jishad Oct 11 '16 at 13:05
  • @JpDevs it doesn't seem to be finding the parent ng-switch – Technohacker Oct 11 '16 at 13:06
  • How can I Solve it – Jishad Oct 11 '16 at 13:08
  • use ng-src not src. that is not solving the problem. can you test your code on chrome ? because when you get an error, you can click on the error in the console and it open an explanation on angular web site – AlainIb Oct 11 '16 at 13:12
  • https://docs.angularjs.org/error/$compile/ctreq?p0=ngSwitch&p1=ngSwitchWhen – Jishad Oct 11 '16 at 13:16

1 Answers1

3
<td ng-switch="category.Status">
    <img ng-switch-when="1" ...></td>
    <img ng-switch-when="0" ...></td>

You're prematurely closing closing the </td> after the first img, the second img is outside the <td> and thereby also outside the scope of ng-switch. The error is caused by ng-switch-when="0" not being able to find a parent ng-switch.

deceze
  • 510,633
  • 85
  • 743
  • 889