Ich, m neu in Angularjs und MongoDB Ich muss HTTP-Anfrage von MongoDB für automatisch vervollständigen eckigen Material, wenn ich an git Hub API senden funktioniert es perfekt, aber für meine DB, ich bekomme length 'undefinierter '' Can not Eigenschaft lesen' mein Controller in Client-SeiteAngularjs http erhalten Anfrage zurück 'Länge' Fehler
/*jslint latedef:false*/
(function() {
'use strict';
angular
.module('clientApp')
.controller('CarnetCtrl', function($http){
this.querySearch = function(query){
//for this link work "https://api.github.com/search/users"
return$http.get("http://localhost:3000/carnet/export_countries/", {
params: {
q: query
}
}).then(function(response){
return response.data.items;
});
};
});
})();
mein Controller für meine MongoDB
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Q = require('q'); // We can now use promises!
//Create Schema
var CarnetExportCountriesSchema = new Schema({
CarnetExportCountriesSchema.statics.getCarnetExportCountries = function(Country_Name_EN) {
var deferred = Q.defer();
this.findOne({Country_Name_EN: Country_Name_EN}, function(error, CarnetExportCountries){
if (error) {
deferred.reject(new Error(error));
}
else {
deferred.resolve(manufacturers);
}
});
return deferred.promise;
}
CarnetExportCountriesSchema);
module.exports = CarnetExportCountriesSchema;
und index.js Server-Seite:
//Add Middleware necessary for REST API's
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(bodyParser.json({type:'application/vnd.api+json'}));
app.use(methodOverride('X-HTTP-Method-Override'));
//CROS Support
app.use(function(req,res,next){
res.header('Access-Control-Allow-Origin','*');
res.header('Access-Control-Allow-Methods','GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers','Content-Type');
res.header('("Content-Length", ""+json.length());');
next();
});
mein app.js
.config(function (
$routeProvider,
RestangularProvider
) {
RestangularProvider.setBaseUrl('http://localhost:3000');
$routeProvider
.when('/main', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
mein Fehler:
TypeError: Cannot read property 'length' of undefined
at hasMatches (angular-material.js:25423)
at shouldShow (angular-material.js:25415)
at shouldHide (angular-material.js:25380)
at setLoading (angular-material.js:25371)
at angular-material.js:25564
at handleCallback (angular.js:17010)
at angular.js:16825
at processQueue (angular.js:16843)
at angular.js:16887
at Scope.$digest (angular.js:17982) "Possibly unhandled rejection: {}"
bitte mich in dieser Angelegenheit helfen ich um 1 Woche suchen und lesen, aber dieses Problem nicht lösen können
Wie erwarten Sie, dass jemand es in diesem Durcheinander findet? Sie müssen Ihren Code auf ein prägnantes Beispiel herunterkochen, das das Problem reproduziert. –
Sorry für mein Durcheinander Ich versuche, einen Teil des Codes zu reduzieren –