I am trying to set a controller object property to an input text that the user enters using ng-model. Although when i log the value using console it returns as undefined, can anyone point out what i might be doing wrong?
Here is my HTML code
<ion-view view-title="Create Goal">
<ion-content>
<form style="margin-top:25px">
<!--Add the input text for the goal's name-->
<div class="content double-padding" style="padding-bottom:0px">
<h4 class="positive">{{ "_goal_name" | translate }}</h4>
<input type="text" ng-model="name" style="border-bottom:1px solid grey;font-size:20px;margin-left:0px;width:100%">
</div>
<!--Add the input range for the goal's distance-->
<div class="content double-padding" style="padding-bottom:0px">
<h4 class="positive">{{ "_goal_distance" | translate }}</h4>
<input type="text" ng-model="distance" style="border-bottom:1px solid grey;font-size:20px;margin-left:0px;width:100%">
</div>
<!--Add the input text for the goal's start date in the form of aaaa-mm-dd-->
<div class="content double-padding" style="padding-bottom:0px">
<h4 class="positive">{{ "_goal_startDate" | translate }}</h4>
<input type="text" ng-model="startDate" style="border-bottom:1px solid grey;font-size:20px;margin-left:0px;width:100%">
</div>
<!--Add the input text for the goal's finish date in the form of aaaa-mm-dd-->
<!--Only appears if the recurring option is true-->
<div ng-show="goals.recurrent" class="content double-padding" style="padding-bottom:0px">
<h4 class="positive">{{ "_goal_finishDate" | translate }}</h4>
<input type="text" name="finishDate" style="border-bottom:1px solid grey;font-size:20px;margin-left:0px;width:100%">
</div>
<!--Add the input checkbox for the goal's recurrence option -->
<!--<ion-toggle ng-model="goals.recurrent" ng-checked="goalRecurrent" toggle-class="toggle-positive">-->
<!--<h4 class="positive" style="font-size:18px;">{{ "_goal_recurrence" | translate }}</h4>-->
<!--</ion-toggle>-->
<!--Add the button that calls the function to save the new goal-->
<div class="content double-padding" style="padding-bottom:0px">
<button ng-click="createGoal()" class="button button-positive button-block">{{ "_button_create" | translate }}</button>
</div>
</form>
</ion-content>
</ion-view>
And here is my Controller code
.controller("GoalFormCtrl", function($scope, $state, $stateParams) {
$scope.createGoal = function() {
$scope.goal = {
name : $scope.name,
distance : $scope.distance,
startDate : $scope.startDate,
// recurrent : $scope.goalRecurrent
};
console.log($scope.goal);
};
})
please check the below link, I have added this in a plunker
ng-controller="GoalFormCtrl"
model value is not getting the controller context
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.