Advertisement
Guest User

Untitled

a guest
May 27th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Em um js separado:
  2. var webServer = "http://dev.utfapp.com/ws/";
  3.  
  4. angular.module('utfapp.services', [])
  5.  
  6. .factory('utfappWS', ['$http', function ($http) {
  7.     return {
  8.         authAluno: function (codigoAluno, senhaAluno, campus) {
  9.             return $http.get(webServer+'auth/aluno', {
  10.                 headers: {
  11.                     'codigoAluno': codigoAluno,
  12.                     'senhaAluno': senhaAluno,
  13.                     'idCampus': campus
  14.                 }
  15.             });
  16.         },
  17.         authBiblioteca: function (codigoAluno, senhaBiblioteca) {
  18.             return $http.get(webServer + 'auth/biblioteca', {
  19.                 headers: {
  20.                     'codigoAluno': codigoAluno,
  21.                     'senhaBiblioteca': senhaBiblioteca,
  22.                 }
  23.             });
  24.         },
  25.     }
  26. }]);
  27.  
  28. No lugar aonde vc inicia o angular vc precisa associar esse módulo 'utfapp.services':
  29.  
  30. No caso do nosso app:
  31. var myApp = angular.module('utfapp', ['ionic', 'utfapp.controllers', 'utfapp.services'])
  32. }])
  33.  
  34.  
  35. Dai em cada controller que vc precisa receber esse factory pra poder usar:
  36. utfappController.controller('BibliotecaCtrl', function ($scope, utfappWS) {
  37. ...}
  38.  
  39.  
  40. E pra usar você só chama a função:
  41.  
  42. utfappWS.authAluno(codigo, senha, campus).success(function (data) {
  43.         console.log(data.results);
  44.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement