【发布时间】:2016-05-19 02:21:13
【问题描述】:
我只是 AngularJs 的新手,还没有完全理解,我有很多问题,这些问题如下:
- 我只想在 onclick 期间点击控制器上的代码,可以吗?
- 或者因为控制器总是在视图加载时加载而不可能?
- 对我来说,创建一个仅在单击按钮时才会触发的函数的最佳方法是什么?而不是每次页面加载。 (AngularJs 方式)
这是我的html:
<ion-view view-title="Account Fixer">
<ion-content class="padding">
<div class="list">
<label class="item item-input item-stacked-label">
<span class="input-label">IrId</span>
<input type="text" placeholder="irid" value="{{irid}}" disabled>
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Email</span>
<input type="text" placeholder="Enter New Email" value="{{email}}">
</label>
<button class="item button button-block button-positive" ng-click="postForm()">Fix Issue</button>
</div>
</ion-content>
</ion-view>
这是我的控制器:
.controller('TestCtrl',function(Test,$scope, $http, $stateParams){
$scope.email = Test.get('AB12345').email;
$scope.irid = Test.get('AB12345').irid;
//I want to hit this during onclick ONLY
$scope.postForm = function(dataForm){
var encodedString = 'action=' +
encodeURIComponent("QA_fixEmail") +
'&irid=' +
encodeURIComponent(Acct.acctData().irid) +
'&email=' +
encodeURIComponent(dataForm.email) +
'&password=' +
encodeURIComponent("abcd1234");
$http({
method: 'POST',
url: 'someservice',
data: encodedString,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data,status){
console.log(status);
})
.error(function(data, status){
console.log(status);
})
}
})
【问题讨论】:
-
到目前为止您所展示的内容应该可以正常工作。它在什么方面不起作用?
-
它正在工作,我想要实现的是,仅在我的 html 按钮单击期间点击 $scope.postForm
标签: javascript angularjs model-view-controller