Skip to content

Instantly share code, notes, and snippets.

@nicholasess
Created February 26, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicholasess/9223784 to your computer and use it in GitHub Desktop.
Save nicholasess/9223784 to your computer and use it in GitHub Desktop.
var Ctrl = angular.module('Controller',['ngRoute','Service']);
Ctrl.controller('Home',function($scope, TextoService,$rootScope){
$scope.title = "Administração - Home";
$scope.textos = [];
TextoService.get(1).then(function(d) {
$scope.textos = d;
$rootScope.textos = d;
});
$scope.Cadastrar = function(){
TextoService.post(1,$scope.titulo,$scope.conteudo,"","");
TextoService.get(1).then(function(d) {
$scope.$watch('textos', function (d, o) {
if (d !== o) {
$scope.textos = d;
};
});
});
$rootScope.reset();
}
});
var Service = angular.module('Service',[]);
Service.factory('TextoService', function($http) {
var promise;
var service = {
get: function(id) {
if ( !promise ) {
promise = $http({
url: 'url',
method: "GET",
cache: false,
params: {id_pagina: id}
}).then(function (response) {
return response.data.retorno;
});
}
return promise;
}
};
return service;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment