我敢肯定我称之为错误,但是我一直在使用Angular 1.6构建的界面。
其他一切都很好,但是此NG点击指令。我的控制器的相关部分,称为" sup"的IngipController在这里:
sup.postForm = function($http){
console.log("postform has been fired.");
$http.post('api/submit', sup.contactInfo)
.then(function(response){
sup.messages.push('Successfully added. Thanks, ' + contactInfo.firstName);
}, function(response){
sup.messages.push('Sorry, this failed. Please try again. n' + response );
});
}
在我的html中,我将功能绑定到这样的按钮:
<button class="btn btn-success" id="submit" ng-click="postForm">Submit</button>
,但不是触发功能。我叫错吗?如果是这样,如何正确执行。
您的功能应为 sup.postForm = function(){....}
您应该在控制器/指令
中注入$ httpangular.module('myApp.controllers', []).
controller('SomeCtrl', ['$scope', '$http', function ($scope, $http) {
// ...
});
然后,您应该在
中打电话给您的html <button class="btn btn-success" id="submit" ng-click="postForm()">Submit</button>