【发布时间】:2016-06-12 21:03:56
【问题描述】:
如何从使用 ng-model 的输入生成的对象中获取值,而不是键和值?
现在已经很接近解决这个问题了
我终于设法通过使用以下代码来防止表中的单个输入值(使用 ng-repeat)显示在每一行的每个相同位置:
<input data-ng-model="newEmail[$index]" type="text" id="newEmail" maxlength="254" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" size="20" class="form-control" placeholder="{{user.email}}">
基本上,我需要获取从 ng-model 输入的值以在我的控制器中使用,我目前正在使用这样的控制器:
$scope.newEmail = {};
$scope.updateProfile = function (profile) {
setTimeout(function () {
console.log('New email is: ', $scope.newEmail);
}, 1000);
};
我遇到的问题是它从输入框中返回一个对象为 { 1: 'whatever text is enter here' }。然后,我似乎无法从对象中获取值来更新 Firebase 中的值,因为它将键和值都写入了我要写入的 Firebase 位置。
一定有一种超级简单的方法可以从我丢失的对象中获取值吗?
【问题讨论】:
-
尝试在对象
$scope.newEmail = []中使用数组 -
传奇!!!它很有效,而且很简单,我应该尝试使用数组 insteaf 对象!谢谢 - 请作为答案发布,我会接受!
-
我怕说它毕竟不起作用:(。好像我点击第一行,输入一个值,点击我的按钮,我会得到这个值。但是,当我在输入框中输入后续值时,它会显示空槽..
标签: javascript jquery html angularjs firebase