У меня проблема с угловым шлейфом sdk. Я настроил проект, созданный фунт-services.js, но когда я пытаюсь вызвать мой API из моих контроллеров консоли браузера говорятloopback angular sdk create не является функцией
"{method name} is not a function".
вот мой код:
index.html
<!DOCTYPE html>
<html lang="en-US">
<head>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"> </script>
<![endif]-->
<base href='/'/>
<script src="vendor/angular/angular.js"></script>
<script src="vendor/angular-resource/angular-resource.js"></script>
<script src="vendor/angular-ui-router/release/angular-ui-router.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/home.js"></script>
<script src="js/controllers/signup.js"></script>
<script src="js/services/lb-services.js"></script>
</head>
<body ng-app="app" ng-controller="HomeCtrl">
<div ui-view></div>
</body>
</html>
app.js
angular.module('app', ['ui.router', 'lbServices'])
//Here are defined routes and controllers
signup.js
angular.module('app')
.controller('SignUpCtrl', ['$scope', '$state', 'Student',function($scope, Student){
$scope.registration = function(){
birth = new Date($scope.formInfo.year, $scope.months.indexOf($scope.formInfo.month), $scope.formInfo.day);
delete $scope.formInfo.year;
delete $scope.formInfo.month;
delete $scope.formInfo.day;
$scope.formInfo.birthday = birth;
Student.create($scope.formInfo)
.$promise
.then(function(student){
console.log(student);
});
};
}]);
где formInfo является нг-модель моей формы. В этом контроллере создан Student.create, который не является функцией. Где моя ошибка? Спасибо за помощь
EDIT Student генерируется командой SDK фунт-нг, которые генерируют фунт-services.js
// CommonJS package manager support
if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.exports === exports) {
// Export the *name* of this Angular module
// Sample usage:
//
// import lbServices from './lb-services';
// angular.module('app', [lbServices]);
//
module.exports = "lbServices";
}
(function(window, angular, undefined) {'use strict';
var urlBase = "/api";
var authHeader = 'authorization';
function getHost(url) {
var m = url.match(/^(?:https?:)?\/\/([^\/]+)/);
return m ? m[1] : null;
}
var urlBaseHost = getHost(urlBase) || location.host;
/**
* @ngdoc overview
* @name lbServices
* @module
* @description
*
* The `lbServices` module provides services for interacting with
* the models exposed by the LoopBack server via the REST API.
*
*/
var module = angular.module("lbServices", ['ngResource']);
module.factory(
"Student",
['LoopBackResource', 'LoopBackAuth', '$injector', function(Resource, LoopBackAuth, $injector) {
var R = Resource(
urlBase + "/students/:id",
{ 'id': '@id' },
{
"create": {
url: urlBase + "/students",
method: "POST"
},
/**
* @ngdoc method
* @name lbServices.Student#createMany
* @methodOf lbServices.Student
*
* @description
*
* Create a new instance of the model and persist it into the data source.
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {function(Array.<Object>,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Array.<Object>} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"createMany": {
isArray: true,
url: urlBase + "/students",
method: "POST"
},
/**
* @ngdoc method
* @name lbServices.Student#upsert
* @methodOf lbServices.Student
*
* @description
*
* Update an existing model instance or insert a new one into the data source.
*
* @param {Object=} parameters Request parameters.
*
* This method does not accept any parameters.
* Supply an empty object or omit this argument altogether.
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"upsert": {
url: urlBase + "/students",
method: "PUT"
},
/**
* @ngdoc method
* @name lbServices.Student#exists
* @methodOf lbServices.Student
*
* @description
*
* Check whether a model instance exists in the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* Data properties:
*
* - `exists` – `{boolean=}` -
*/
"exists": {
url: urlBase + "/students/:id/exists",
method: "GET"
},
/**
* @ngdoc method
* @name lbServices.Student#findById
* @methodOf lbServices.Student
*
* @description
*
* Find a model instance by id from the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* - `filter` – `{object=}` - Filter defining fields and include
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"findById": {
url: urlBase + "/students/:id",
method: "GET"
},
/**
* @ngdoc method
* @name lbServices.Student#find
* @methodOf lbServices.Student
*
* @description
*
* Find all instances of the model matched by filter from the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `filter` – `{object=}` - Filter defining fields, where, include, order, offset, and limit
*
* @param {function(Array.<Object>,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Array.<Object>} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"find": {
isArray: true,
url: urlBase + "/students",
method: "GET"
},
/**
* @ngdoc method
* @name lbServices.Student#findOne
* @methodOf lbServices.Student
*
* @description
*
* Find first instance of the model matched by filter from the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `filter` – `{object=}` - Filter defining fields, where, include, order, offset, and limit
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"findOne": {
url: urlBase + "/students/findOne",
method: "GET"
},
/**
* @ngdoc method
* @name lbServices.Student#updateAll
* @methodOf lbServices.Student
*
* @description
*
* Update instances of the model matched by where from the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `where` – `{object=}` - Criteria to match model instances
*
* @param {Object} postData Request data.
*
* This method expects a subset of model properties as request parameters.
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* The number of instances updated
*/
"updateAll": {
url: urlBase + "/students/update",
method: "POST"
},
/**
* @ngdoc method
* @name lbServices.Student#deleteById
* @methodOf lbServices.Student
*
* @description
*
* Delete a model instance by id from the data source.
*
* @param {Object=} parameters Request parameters.
*
* - `id` – `{*}` - Model id
*
* @param {function(Object,Object)=} successCb
* Success callback with two arguments: `value`, `responseHeaders`.
*
* @param {function(Object)=} errorCb Error callback with one argument:
* `httpResponse`.
*
* @returns {Object} An empty reference that will be
* populated with the actual data once the response is returned
* from the server.
*
* <em>
* (The remote method definition does not provide any description.
* This usually means the response is a `Student` object.)
* </em>
*/
"deleteById": {
url: urlBase + "/students/:id",
method: "DELETE"
}
)
Это кусок фунт-services.js ,
Вам необходимо предоставить код Student для людей, чтобы быть в состоянии помочь. –
Я думаю, что вам не хватает одной из введенных вами услуг. Не должен '.controller ('SignUpCtrl', ['$ scope', '$ state', 'Student', function ($ scope, Student)' быть следующим: '.controller ('SignUpCtrl', ['$ scope' , '$ state', 'Student', function ($ scope, $ state, Student) '? –
Нет. Он дал мне ту же ошибку :( – Daigo