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 两次
你的意思是:
被打印了两次?
那大概是因为你在页面又引用了一次mctrl ,去掉ng-controller="mctrl" 试试