$stateParmas作为参数传入时失败,下载了老师的代码之后想要把请求数据的操作放到service中,却遇到了这样的问题
var myServiceApp = angular.module('myServiceApp',[]); myServiceApp.factory('bookservice', ['$http', '$stateParams', function($http, $scope, $state, $stateParams){ var service = { test: function(){ console.log($stateParams); console.log("service success!"); }, getdata: function(){ //console.log($stateParams.booktype); //return $http.get("./data/book4.json"); //.success(function(){console.log("getdata success!");}); return $http({ method: "GET", url: "./data/" + $stateParams.booktype + ".json" }); } }; return service; } ]);
会报错
TypeError: Cannot read property 'booktype' of undefined
这是怎么一回事,谢谢^_^