javascript - Angular Attribute Always Undefined -
i trying bind css class using angularjs function. it's working printing many error on browser console. can please me on matter??. have attached code , screenshot below.
<tr ng-repeat-start="inventory in inventorydetails.hotelfareinventoryallotmentdetails"> <td rowspan="2">{{inventory.hotelroomcategoryname}}</td> <td>inventory</td> <td ng-class="getclassname(1)">{{inventory.d1.inventory}}</td> <td ng-class="getclassname(2)">{{inventory.d2.inventory}}</td> <td ng-class="getclassname(3)">{{inventory.d3.inventory}}</td> {{inventory.d31.inventory}}</td> </tr> <tr ng-repeat-end> <td>cutoff</td> <td ng-class="{{getclassname(1}})">{{inventory.d1.cutoff}}</td> <td ng-class="getclassname(2)">{{inventory.d2.cutoff}}</td> <td ng-class="getclassname(3)">{{inventory.d3.cutoff}}</td> </tr>
$scopechild.getclassname = function (dayid) { var dayindex = parseint(dayid) - 1; if ($scopechild.days[dayindex].isweekend) { return 'weekend'; } else { return ''; } }
from error can see $scopechild
exists , has member called days
. however, $scopechild.days[dayindex]
undefined
. result, isweekend
not existent property of undefined
object. result, error. there 2 cases:
- you might want make sure
$scopechild.days[dayindex]
exist whenever call function, fixing logic of code - you might want make sure error not happen, if
function
called in wrong way
if want write library, need idiot-proof solution, if problem lies in algorithm, need rethink it. instance, if 1 looks @ dayid
, he/she should realize values of dayid
should either between 0..6 or 1..7. id of monday in case? sure parameter dayid
numeric? no trailing white characters? number existent in days
? etc., etc. bet problem algorithm flawed , suggest should debug. example:
$scopechild.getclassname = function (dayid) { var dayindex = parseint(dayid) - 1; if (!$scopechild.days[dayindex]) { dayindex = "busted..."; //put breakpoint here , see happens return; } if ($scopechild.days[dayindex].isweekend) { return 'weekend'; } else { return ''; } }
also, vkrishna pointed out, have syntax error, is, close paranthesis not opened. , finally, advisable paste error question instead of attaching image.
Comments
Post a Comment