How to get service function to controller in AngularJS version 1.6.1 -


i have trouble on script, want data database using json output.

[{"id_admin":"2","username":"mac","password":"macgeeky","nama_lengkap":"mac geeky"}] 

here angular script :

app.controller('welcomecontrol', ['$scope', function($scope){     $scope.head_msg = {         head: 'control panel',         body: 'ini merupakan halaman yang hanya dapat diakses oleh administrator, pada bagian atas dan samping kiri halaman website ' +               'terdapat beberapa menu yang dapat ditelusuri untuk melakukan pengelolaan informasi.'     };      $scope.img_wel = './images/icon_topsis.png';     $scope.welcome_text = 'selamat datang di aplikasi penilaian guru teladan pada dinas pendidikan dengan menggunakan ' +                           'metode topsis.'; }]);  app.controller('administratorcontrol', ['$scope', 'administratorservice', '$http', function($scope, administratorservice, $http) {     $scope.head_msg = {         head: 'administrator',         body: 'pada halaman ini anda dapat melakukan pengelolaan data administrator'     }      $scope.data = administratorservice.getlistdata('./sys/mac.php?act=administrator'); }]);  app.service('administratorservice', ['$http', function($http){     this.getlistdata = function(link){         $http({url: link})         .then(function(response) {             return response.data;         });     } }]); 

how service function controller in angularjs? using angular js version 1.6.1 way.

change service , administratorcontrol controller

.controller('administratorcontrol', function($scope, administratorservice) {       $scope.head_msg = {             head: 'administrator',             body: 'pada halaman ini anda dapat melakukan pengelolaan data   administrator'        }      administratorservice.getlistdata('./sys/mac.php?act=administrator')        .then(function(data) {          console.log(data)        });    })    .service('administratorservice', ['$http', '$q', function($http, $q) {      this.getlistdata = function(link) {        var deferred = $q.defer();         $http({            url: link          })          .then(function(response) {            deferred.resolve(response.data);          });        return deferred.promise;      }     }]) 

checkout fiddle


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -