我新的角度和Deployd,不知道如何一起使用它们。
我发现Deployd网站很好的例子,但它不仅耗费REST API的数据,我想了解如何有Deployd作为内部AngularJS的服务。例如,保持所有客户端的API了最新的集合与在deployd可收集事件最新数据。
我想出了下面的例子中,我们可以看到,我使用$资源消耗REST API,但控制器MyCtrl里面,我打电话DPD,我想用它来充分利用的功能,如 http://docs.deployd.com/docs/collections /notifying-clients.md
我真的很想看到一些例子,或有关本的任何意见!
感谢您寻找:)
angular.module('问题',['ngResource']).factory('Deployd',函数(DPD){ 返回DPD;}).factory('EntriesService',函数($资源){ 返回$资源('/项',{});}).controller('MainCtrl',['$范围,EntriesService',函数($范围,EntriesService){ $ scope.title =Q&安培; A模块; $ scope.entries = []; EntriesService.query(功能(响应){ $ scope.entries =响应; }); $ scope.addMessage =功能(){ $ scope.entries.push({ 作者:myAuthor 消息:$ scope.message }); EntriesService.save({ 作者:myAuthor 消息:$ scope.message }); }; dpd.comments.get(功能(评论,错误){ comments.forEach(功能(评论){ 的console.log(注解); }); });}]);
解决方案
我找到了解决办法。这可以为其他人在未来有帮助的:
angular.module('问题',['ngResource']).factory('Deployd',函数(){ 返回DPD;}).factory('EntriesService',函数($资源){ 返回$资源('/项',{});}).controller('MainCtrl',['$范围,EntriesService','Deployd',函数($范围,EntriesService,Deployd){ $ scope.title =Q&安培; A模块; $ scope.entries = []; EntriesService.query(功能(响应){ $ scope.entries =响应; }); $ scope.addMessage =功能(){ VAR作者=myAuthor; VAR消息= $ scope.message; Deployd.entries.post({ 作者:作者, 消息:消息 },功能(评论,错误){ 如果(错误){ 返回showError(错误); } $ scope.entries.push({ 作者:作者, 消息:消息 }); }); }; Deployd.entries.on('创造',函数(){ EntriesService.query(功能(响应){ $ scope.entries =响应; }); });}]);
I'm new to Angular and Deployd and wondering how to use them together.
I found the example in Deployd website nice, but it's only consuming rest API data and I'd like to understand how to have Deployd as a service inside AngularJS. For example, keeping all of the clients API up-to-date with the collection's latest data with collection events available in deployd.
I came up with the example below, where we can see that I'm using $resource to consume the rest api, but inside the controller "MyCtrl", I'm calling dpd, that I'd like to use to take advantage of features such as http://docs.deployd.com/docs/collections/notifying-clients.md
I'd really like to see some examples, or any advice concerning this!
Thanks for looking :)
angular.module('questions', ['ngResource'])
.factory('Deployd', function(dpd){
return dpd;
})
.factory('EntriesService', function($resource){
return $resource('/entries', {});
})
.controller('MainCtrl', ['$scope', 'EntriesService', function($scope, EntriesService) {
$scope.title = "Q&A Module";
$scope.entries = [];
EntriesService.query(function(response){
$scope.entries = response;
});
$scope.addMessage = function() {
$scope.entries.push({
author: "myAuthor",
message: $scope.message
});
EntriesService.save({
author: "myAuthor",
message: $scope.message
});
};
dpd.comments.get(function(comments, error) {
comments.forEach(function(comment) {
console.log(comment);
});
});
}]);
解决方案
I found a solution. This may be helpful in the future for someone else:
angular.module('questions', ['ngResource'])
.factory('Deployd', function(){
return dpd;
})
.factory('EntriesService', function($resource){
return $resource('/entries', {});
})
.controller('MainCtrl', ['$scope', 'EntriesService', 'Deployd', function($scope, EntriesService, Deployd) {
$scope.title = "Q&A Module";
$scope.entries = [];
EntriesService.query(function(response){
$scope.entries = response;
});
$scope.addMessage = function() {
var author = "myAuthor";
var message = $scope.message;
Deployd.entries.post({
author: author,
message: message
}, function(comment, error) {
if (error) {
return showError(error);
}
$scope.entries.push({
author: author,
message: message
});
});
};
Deployd.entries.on('create', function() {
EntriesService.query(function(response){
$scope.entries = response;
});
});
}]);