suchen

Heim  >  Fragen und Antworten  >  Hauptteil

angular.js - angular route controller $http 请求两次

app.config(['$routeProvider', function($routeProvider){
    $routeProvider.when('/', {
        templateUrl: tplPath + '/posts.html',
        controller: 'mctrl'
    });
}]);

app.controller('mctrl', ['$scope', '$http', '$log', handleMctrl]);

function handleMctrl($scope, $http, $log) {
    var self = this;
    console.log(self);
    var resp = $http.get('/post/new');

    resp.success(function (data, status, headers, config) {
        $log.debug(data);
        self.data = data;
    });
};

会请求 /pot/new 两次

phpcn_u1582phpcn_u15822822 Tage vor528

Antworte allen(2)Ich werde antworten

  • 大家讲道理

    大家讲道理2017-05-15 16:59:18

    你的意思是:

    console.log(self)

    被打印了两次?

    Antwort
    0
  • 世界只因有你

    世界只因有你2017-05-15 16:59:18

    那大概是因为你在页面又引用了一次mctrl ,去掉ng-controller="mctrl" 试试

    Antwort
    0
  • StornierenAntwort