当我通过ng-click

时间:2016-09-29 08:13:35

标签: angularjs ionic-framework

我正在尝试设计一个视图,只需通过ng-model获取firstName和lastName,然后通过ng-click将其传递给控制器​​中的CreateAccount函数。我似乎无法正常工作并且在控制台中,即使在填写所有细节之后,firstName和lastName的值也显示为undefined。

HTML

<ion-view title="USER">
    <ion-nav-buttons side="right">
        <p ng-click="CreateAccount(FirstName,LastName)">
           SAVE
        </p>
    </ion-nav-buttons>
<ion-content>    
    <md-input-container md-no-float="">
        <div>
            <input class="user-name" 
                   placeholder="First Name"
                   ng-model="FirstName">
        </div>
    </md-input-container>
    <md-input-container md-no-float="">
        <div>
            <input class="user-name" 
                   placeholder="Last Name"
                   ng-model="LastName">
        </div>
    </md-input-container>
</ion-content>  
</ion-view>

控制器

$scope.CreateAccount = function(FirstName,LastName){
    console.log(FirstName);
    console.log(LastName);
}

1 个答案:

答案 0 :(得分:0)

你应该有变量defiend,如果你有$ scope变量,则不需要在函数内部传递

  $scope.person = {
       firstName: "Nikhil",
       lastName: "Hegde"
     };
     $scope.save =function() {
       console.log($scope.person.firstName);
        console.log($scope.person.lastName);
     };

DEMO