AngularJS-TypeError:cribsFactory2.getCribs2(...)。then(...)。error不是函数

时间:2018-11-10 21:14:50

标签: angularjs

我遇到以下错误: angular.min.js:125 TypeError:cribsFactory2.getCribs2(...)。then(...)。error不是函数     在对象。 (cribsController3.js:12)

我找到了有关此错误的一些主题,但无法解决该问题(我对代码进行了一些更改,但没有运气)。有人能帮我吗?

这是我正在使用的文件:

cribsFactory2.js

angular
.module('ngCribs')
.factory('cribsFactory2', function($http) {

function getCribs2() {
return $http.get('scripts/data.json');
}

return {
getCribs2: getCribs2
}
});

cribsController3.js

angular
.module('ngCribs',[])
.controller('cribsController3', function($scope, cribsFactory2) {

$scope.cribs2;

cribsFactory2.getCribs2()
.then(function(response) {
$scope.cribs2 = response;               ;
})
.error(function(error) {
console.log(error);
});
});

app.html

<body ng-app="ngCribs" ng-controller="cribsController3">
<div class="well" ng-repeat="crib in cribs2">
<h3>{{crib.address}}</h3>
<p><strong>Type: </strong> {{crib.type}}</p>
<p><strong>Description</strong> {{crib.description}}</p>
<p><strong>Price</strong> {{crib.price}}</p>
</div>

0 个答案:

没有答案