搜尋

首頁  >  問答  >  主體

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_u15822869 天前559

全部回覆(2)我來回復

  • 大家讲道理

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

    你的意思是:

    console.log(self)

    被印了兩次?

    回覆
    0
  • 世界只因有你

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

    那大概是因為你在頁面又引用了一次mctrl ,去掉ng-controller="mctrl" 試試

    回覆
    0
  • 取消回覆