gpt4 book ai didi

javascript - 我无法访问 Controller 中的输入字段 - AngularJS

转载 作者:行者123 更新时间:2023-12-03 10:22:57 25 4
gpt4 key购买 nike

我正在使用使用 AngularJS 的 Ionic 框架,我无法访问 Controller 中的输入字段“groupName”,我只是得到“未定义”。

我认为使用 ng-model 会将其注入(inject)我的 Controller 范围内?

<ion-pane>
<ion-header-bar align-title="left" class="bar-positive">
<div class="buttons">
<button class="button" ng-click="saveNewGroup()">Save</button>
</div>
</ion-header-bar>
<ion-content>
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Name" ng-model="groupName">
</label>
</div>
</ion-content>

我的 Controller 中的代码:

$scope.saveNewGroup = function() {
console.log($scope.groupName); // prints "undefined" all the time
};

最佳答案

在 Controller 中定义 $scope.groupName

您似乎没有在 Controller 中定义它,因此您正在尝试访问 undefined variable 。定义它,并将正确的 Controller 应用到模型,您会发现它正确地绑定(bind)了数据。

干杯。

编辑:很高兴它有效。

enter image description here

关于javascript - 我无法访问 Controller 中的输入字段 - AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29543986/

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