-
-
Save allanfreitas/9232303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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