angular.js - angular route controller $http 请求两次
phpcn_u1582
phpcn_u1582 2017-05-15 16:57:18
0
2
490
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_u1582
phpcn_u1582

reply all(2)
大家讲道理

You mean:

console.log(self)

Printed twice?

世界只因有你

That’s probably because you referenced mctrl again on the page. Try removing ng-controller="mctrl"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template