我正在尝试将我的Web应用程序连接到mongoose的后端服务器。此服务器目前在本地托管。
我正在尝试从服务器获取一个“recipe”对象并获取其标题。 我收到以下错误:
angular-ui-router.js:18未捕获的类型错误:无法读取未定义的属性“isDefined”(匿名函数)@ angular-ui-router.js:18(匿名函数)@ angular-ui-router.js:3223 angularApp.js:3未捕获的引用错误:未定义angular 我正在使用Post Man获取我的对象。
我们的HTML页面。
我正在尝试从服务器获取一个“recipe”对象并获取其标题。 我收到以下错误:
angular-ui-router.js:18未捕获的类型错误:无法读取未定义的属性“isDefined”(匿名函数)@ angular-ui-router.js:18(匿名函数)@ angular-ui-router.js:3223 angularApp.js:3未捕获的引用错误:未定义angular 我正在使用Post Man获取我的对象。
[
{
"_id": "56309ea8e4b02bf207dbe409",
"title": "Chili sin carne",
}
]
我们的HTML页面。
<html>
<head>
<title>Recipes</title>
<link rel='stylesheet' href='/stylesheets/inlog.css' />
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui- router/0.2.10/angular-ui-router.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js"></script>
<script src="javascripts/angularApp.js"></script>
</head>
<body>
<table >
<div ng-controller="RecipesCtrl">
<h1>Title </h1>
//here we load a recipe object and get it's title and show it
<p>{{$scope.title}}</p>
</div>
</body>
</html>
Javascript
'use strict';
var app = angular.module('project-eva', []);
app.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider,$urlRouterProvider){
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl',
})
.state('login', {
url: '/login',
templateUrl: '/login.html',
controller: 'loginCtrl',
onEnter: ['$state', 'auth', function($state, auth){
if(auth.isLoggedIn()){
$state.go('home');
}
}]
})
.state('register', {
url: '/register',
templateUrl: '/register.html',
controller: 'AuthCtrl',
onEnter: ['$state', 'auth', function($state, auth){
if(auth.isLoggedIn()){
$state.go('home');
}
}]
})
.state('recipes', {
url: '/recipes',
templateUrl: '/recipes.html',
controller: 'RecipeCtrl',
onEnter: ['$state', 'auth', function($state, auth){
if(auth.isLoggedIn()){
$state.go('home');
}
}]
});
$urlRouterProvider.otherwise('home');
}]);
app.factory('recipes', ['$http' ,function($http){
var o = {
recipes: []
};
o.getAll = function(){
return $http.get('/recipes').success(function(data){
angular.copy(data,o.recipes);
});
};
return o;
}]);
食谱控制器
var app = angular.module('project-eva')
app.controller('RecipesCtrl', function ($scope, $location, $rootScope, $http) {
"use strict";
$scope.recipes = function(){
$http({
method: 'GET',
url: 'localhost:8080/api/recipes',
headers: {
'Access-Control-Allow-Origin' : '*',
'Content-Type': 'application/json'
},
data: {
title : $scope.title;
}
}).then(function succesCallBack(response){
console.log(response);
}, function errorCallback(response){
console.log(response);
if(response.data !== null){
$scope.error = response.data.message;
} else {
$location.path('/ise');
}
});
} else {
$scope.error = "Please fill in all required fields.";
}
} else {
$scope.error = "Password and confirm password have to be te same!";
}
}
});