search

Home  >  Q&A  >  body text

jquery - Angular js how to call service in controller.

hoemApp.controller('homeController', ['$http', '$scope', '$interval', 'homecharts', function ($http, $scope, $interval, homecharts) {

    // controller 内容 , 怎么调用 service

}]).service('homecharts', ['$http', '$rootScope', '$interval', function ($http, $scope, $interval) {

    $http({
        method: 'GET',
        params: {username: "admin"},
        url: 'http://localhost:9090/homevm'
    }).success(function (data, status, headers, config) {
        $scope.infoData = data;
    }).error(function (data, status, headers, config) {
    });

My service here does not need to return any data. All data assignments are completed in the service.
Now I want to use routeProvider to realize the display of ng-view.
But routeProvider.when( ) method specifies a controller, but my current controller does not call the service.
How should I call the service in the controller?

某草草某草草2830 days ago580

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 17:01:41

    This link was written by a person 2 years ago, it is very detailed

    reply
    0
  • Cancelreply