我是新手,我可以应用CRUD操作。现在我想从Angular JS的视图中调用Node JS控制器中的更多操作,并且我将这个链接https://github.com/jpotts18/mean-stack-relational称为核心模型。
这是控制器文件design.js
exports.get_designs = function(req, res) {
console.log('in design node controllrrrrr get designs');
db.designs.findAll({ where: {competition_id: req.params.competitionId} }).success(function(designs){
return res.jsonp(designs);
}).error(function(err){
return res.render('error', {
error: err,
status: 500
});
});
};
在角度控制器中
angular.module('mean.designs').controller('DesignsController', ['$scope', '$routeParams', '$location', 'Global', 'Designs',function($scope, $routeParams, $location, Global, Designs) {
$scope.global = Global;
$scope.get_init_records = function() {
console.log('in get init records comp id : ' + JSON.stringify($routeParams.competitionId));
Designs.query({
competitionId: $routeParams.competitionId
}, function(designs) {
console.log(designs);
$scope.designs = designs;
});
};
}]);
和服务设计.js
angular.module('mean.designs').factory("Designs", ['$resource', function($resource) {
return $resource('designs/:designId', {
designId: '@id'
}, {
update: {
method: 'PUT'
}
});
}]);
在视图中
<section data-ng-controller="DesignsController" data-ng-init="get_init_records()" />
我可以调用get_init_records这个init方法,但后来我不知道那里发生了什么......当我用google搜索结果时使用$ http但是如何做到这一点?谢谢你的帮助