angular.js - angular route controller $http request twice
phpcn_u1582
phpcn_u1582 2017-05-15 16:57:18
0
2
506
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;
    });
};

Will request /pot/new twice

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