简体   繁体   中英

angular js TypeError: Cannot read property 'toLowerCase' of undefined

habilitationCtrl.groupSort = function(g1, g2) {
   if (g1.nom.toLowerCase() < g2.nom.toLowerCase()) 
     return -1;
   else if (g1.nom.toLowerCase() == g2.nom.toLowerCase()) 
     return 0;
   else return 1;
}

I have this error TypeError: Cannot read property 'toLowerCase' of undefined

@BiginByHelloWord - Hey wrap your functionality inside an if statement, which checks if the g1,g2 ,g1.nom and g2.nom are not undefined.

If(g1 && g2 && g1.nom && g2.nom)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM