【发布时间】:2015-11-29 05:06:02
【问题描述】:
我尝试在我的 chrome 扩展中使用过滤器 angularjs 服务。但我不知道如何在我的函数中获取/注入它。 目前我有:
chrome.contextMenus.onClicked.addListener(function(info, tab) {
result = $filter('filter')(jsonArray, info.selectionText, function (actual, expected) {
return actual.toString().toLowerCase().indexOf(expected.toLowerCase()) == 0;
});
console.log(sug);
});
但显然我有:$filter 没有定义。 我也想使用 $http 服务来获取我的 jsonArray
【问题讨论】:
-
在函数所在的controller/provider/module中注入依赖
-
我没有控制器/提供者/模块。我只想单独使用过滤器。
-
您不需要所有的角度来过滤数组。它自 ES5 以来内置,请参阅 developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
-
好的!但我也使用 $http 来获取我的 json 数组。所以一般来说如何在没有控制器/提供者/模块的情况下使用 angularjs 服务?
标签: javascript angularjs google-chrome-extension