Restangular - _.contains() is not a function

匆匆过客 提交于 2019-12-12 10:49:55

问题


If you have recently updated restangular through bower it will have installed the latest lodash - the new 4.0. However this is a problem as restangular/angular now throws the error - "_.contains() is not a function."

How do you solve?


回答1:


The solution is very simple - you need to tell restangular to use a lower version than the newest lodash - 3.10.0

Through bower.json

 "lodash": "~3.10.0"

https://github.com/mgonto/restangular/issues/1298




回答2:


If you have not specified the entry for lodash explicitly and this gets installs as a dependency of restangular, you can uninstall both of them and reinstall lodash (3.10.1) to fix the issue.

bower uninstall restangular
bower uninstall lodash
bower install --save lodash#3.10.1
bower install --save restangular

This way you would not need an entry into the bower.json file.

Source: https://github.com/mgonto/restangular/issues/1294




回答3:


Couldn't you put this in app.js

// If Restangular ever updates to lodash 4.0 remove this.
_.contains = _.includes


来源:https://stackoverflow.com/questions/34922682/restangular-contains-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!