2017-06-21 98 views
0

以下是我的角度應用程序的外觀。如何調用頁面加載角度服務的功能

(function() { 
    "use strict"; 

angular 
    .module("app.core", ['ngRoute']); 

}()); 

服務

(function() { 

'use strict'; 

angular 
    .module('app.service') 
    .factory('dataService', dataService); 

dataService.$inject = ['$http', '$q']; 

function dataService($http, $q) { 

    var service = { 
     create: create, 
     read: read, 
     update: update, 
     remove: remove 
    } 

    return service; 

    function read() { 
     return 
     $http.get("APIURL") 
     .then(success) 
     .catch(exception); 

     function success(response) { 

     } 

     function exception(ex) { 

     } 

    } 

    function create() {} 
    function update() {} 
    function detete() {} 

} 
})` 

的index.html

<body ng-app="app.core"> 
    <div ng-view> </div> 
    </div> 

在頁面加載,家庭template.html插入到NG-視圖。

下面

什麼是正確的方式DataService的只讀過的頁面 負載()調用沒有線索?

+0

[在頁面加載呼叫功能Angularjs]的可能的複製(https://stackoverflow.com/questions/27194805/angularjs-on-page-load-call-function) –

回答