我在我的员工管理应用程序中使用 angular js。我能够从 couchdb 生成 JSON,如下所示:
[
{
"id": "123",
"name": "Henry",
"address": "HSR"
},
{
"id": "456",
"name": "Erik",
"address": "Kormangala"
}
]
我什至可以看到在 Firebug 的 NET 面板中加载的 JSON。这是我的 Angular JS 文件:Employee_Manager_App.js:
var EMApp= angular.module('EMApp', ['employeeProvider']).config(function ($routeProvider){
$routeProvider.when("/", {
templateUrl: '../EMApp/resources/html/login.html',
controller: 'LoginController'
});
$routeProvider.when("/home",{
templateUrl : '../EMApp/resources/html/home.html',
controller: 'HomeController'
});
$routeProvider.otherwise({redirectTo: '/' });
});
EMApp.controller('LoginController', function($scope, $location){
$scope.login = function(){
if($scope.credentials.username === "admin" && $scope.credentials.password === "1234")
$location.path('/home');
else
alert("Username should be admin & Password should be 1234");
};});
EMApp.controller('HomeController', function($scope, Employees){
$scope.employeeRes = Employees.query();
console.log($scope.employeeRes);});
employee_provider.js:
angular.module('employeeProvider',['ngResource']).
factory('Employees', function($resource){
var Employees = $resource('http://localhost\\:5984/myapp/_design/mydesign/_show/employee_shows/9351c38f9a64fd26e40b2ac4cf012efe?name=:value', {value : "employees"}, {query : {method : 'JSONP'}});
return Employees;
});
即使我可以看到 JSON 作为响应,在我使用“employeeRes”的 html 页面上也没有看到员工详细信息。
有人看到有什么不对吗?请纠正我。提前致谢。