用于访问工厂对象中函数的Angularjs语法
我的工厂创造了这样的资源用于访问工厂对象中函数的Angularjs语法,angularjs,factory,Angularjs,Factory,我的工厂创造了这样的资源 (function () { "use strict"; angular .module("common.services") .factory("personResource", ["$resource", personResource]); function personResource($resource) {
(function () {
"use strict";
angular
.module("common.services")
.factory("personResource",
["$resource",
personResource]);
function personResource($resource) {
return {
cnTys: $resource("/api/contentTypes")
}
}
}());
我觉得我应该能做到这一点
app.config(["$stateProvider",
"$urlRouterProvider",
"personResourceProvider",
function ($stateProvider, $urlRouterProvider, personResourceProvider) {
personResourceProvider
.$get()
.cnTys
.query(function (data) {
var valueArray = data
});
其中变量valueArray存储数据JSON响应。但是,当它运行函数CnTys时,它是未定义的。查看控制台中的personResourceProvider对象,它存在,但在调用$get后仍然为空
我忽略了什么?我正在尝试修改示例解决方案,这方面我是新手。只需删除。$get行此处我使用personResourceProvider.cnTys.query…删除。$get无效。对象仍然为空,并且我得到了TypeError:无法读取undefinedTry的属性'query',调试personResourceProvider和/或personResourceProvider的值。$get在浏览器中
personResourceProvider: Object
$get: enforcedReturnValue()
arguments: [Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
caller: [Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
length: 0
name: "enforcedReturnValue"
prototype: enforcedReturnValue
__proto__: ()
<function scope>
__proto__: Object