我无法在我的控制器中访问我的输入字段 - AngularJS

I can't access my input field in my controllar - AngularJS

我正在使用使用 AngularJS 的 Ionic 框架,但我无法在我的控制器中访问我的输入字段 "groupName",我只得到 "undefined"。

我认为使用 ng-model 会在我的控制器范围内注入它?

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

我控制器中的代码:

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

在你的控制器中定义 $scope.groupName

你似乎没有在你的控制器中定义它,所以你试图访问一个未定义的变量。定义它,并将正确的控制器应用于模型,您会发现它的数据绑定正确。

干杯。

编辑:很高兴它起作用了。