我有这样的代码跟工厂:无法从工厂数据传递到控制器
angular.module("mainApp", ["kendo.directives"])
.factory("getFormats", function() {
var searchStr="list&John&1&1".substr(1);
//Here I see the searchStr
return {
isType: function(){
searchStr.split('&')[0];
//Here I see the searchStr
},
username: function(){
searchStr.split('&')[1];
},
dateFormatIndex: function(){
searchStr.split('&')[2];
},
languageIndex: function(){
searchStr.split('&')[3];
}
}
})
.controller("ValidationListCtrl", function($scope,getFormats) {
var isType=getFormats.isType(); //Here I see the undefined
var username=getFormats.username();//Here I see the undefined
var dateFormatIndex=getFormats.dateFormatIndex();//Here I see the undefined
var languageIndex=getFormats.languageIndex();//Here I see the undefined
}
但我得到为未定义在控制器中的所有变量。我还检查了工厂,当我在控制器得到它,看到它与空对象
Object {}dateFormatIndex:(){arguments: nullcaller: nulllength: 0name: ""prototype: dateFormatIndex__proto__: Empty() {}<function scope>isType:(){languageIndex:(){username:(){__proto__: Object
我失去了什么?
非常感谢您的回答! –