AngularJs代码效率mvc框架

时间:2016-05-19 02:21:13

标签: javascript angularjs model-view-controller

我刚认识AngularJs并且尚未了解整个事情,我有很多问题,这些问题如下:

  1. 我想在onc​​lick期间点击控制器上的代码,是否可以?
  2. 或者它是不可能的,因为在视图加载时总是加载控制器?
  3. 对我来说,创建一个仅在点击按钮期间才能点击的功能的最佳方法是什么?而不是每次页面加载。 (AngularJs方式)
  4. 这是我的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);
        })
    }
    })
    

1 个答案:

答案 0 :(得分:1)

问:是否有可能......仅在onclick期间[点击功能]?

<答案A:是的,当然。只需使用ngClick

即可

以下是一些例子:

AngularJS Events

请注意,一个链接使用ng-click,另一个链接使用ngClick。这些是等价的:

AngularJS, ng-click vs ng:click vs ngClick

相关问题