gpt4 book ai didi

javascript - ng-model 绑定(bind)在 Controller 中返回未定义

转载 作者:行者123 更新时间:2023-11-30 19:49:41 25 4
gpt4 key购买 nike

我正在尝试将 Controller 对象属性设置为用户使用 ng-model 输入的输入文本。虽然当我使用控制台记录值时它返回未定义,但任何人都可以指出我可能做错了什么吗?

这是我的 HTML 代码

<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>

这是我的 Controller 代码

.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);
};
})

最佳答案

请检查下面的链接,我已经在plunker中添加了这个

ng-controller="GoalFormCtrl"

模型值未获取 Controller 上下文

http://plnkr.co/edit/81Vi92bQjjhQxsIw1axD

关于javascript - ng-model 绑定(bind)在 Controller 中返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54601721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com