JpDevs JpDevs - 16 days ago 6
AngularJS Question

Angular JS ng-switch not working

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 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>
<img src="{{URL::asset('public/assets/images/icons/ic_inactive.png')}}">

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]$compile/ctreq?p0=ngSwitch&p1=ngSwitchWhenN/<@http://localhost/repos/p3-laravel/ppp_admin/public/js/angular.min.js:6:412

<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.