从模板中获取ng-model值
Getting ng-model value from template
我有离子模态模板,看起来像:
<ion-modal-view>
<ion-header-bar>
.....
</ion-header-bar>
<ion-content>
...
<input class="form-input" type="text" ng-model="relation"/>
...
</ion-content>
</ion-modal-view>
controller: $scope.resolve = function () {
console.log('relation', $scope.relation);
}
我需要从解析函数内的relation
模型中获取值,但它是未定义的。我怎样才能得到它呢?
感谢关注!
这对我有效,请查看
我已经更新了你的Ionic-modal模板
<ion-modal-view>
<ion-content>
<input class="form-input" type="text" ng-model="test.relation"/>
<button class="button button-bar button-positive" ng-click="answerswer()">Click Me</button>
</ion-content>
</ion-modal-view>
在您的控制器中,请将代码更新为:
$scope.test = {};
$scope.answer = function(){
console.log($scope.test.relation);
}
"如果你使用ng-model,你必须在那里有一个点。"
让你的模型指向一个对象。属性,你就可以走了。
导致这种情况的问题是嵌套状态。你可以在AngularJS中找到更多关于嵌套作用域的信息。
控制器$scope.form = {};
$scope.resolve = function () {
console.log('relation', $scope.form.relation);
}
测试模板<ion-modal-view>
<ion-header-bar>
.....
</ion-header-bar>
<ion-content>
...
<input class="form-input" type="text" ng-model="form.relation"/>
...
</ion-content>
相关文章:
- 从 Javascript 中设置 ng-model name
- Toggle Switch在包含ng model和ng repeat之后不进行切换
- 在Angularjs中,我如何使用ng repeat、ng model和ng click来动态更改内容
- 使用 ng 模型获取数据时遇到问题
- 当与之关联的 ng-model 为 false 时,Angularjs 复选框值不会取消选中
- angularJS从ng-repeat获取类名
- ng-model 绑定到选择标签生成的空默认值
- 对象不能在angularjs ng-model中访问
- 为什么 HTML 中的 Value 属性在与 AngularJS 中的 ng-model 一起使用时不起作用
- 当输入ng-model是ngRepeat变量时,如何从输入数据中获取
- NG-model 未定义多种方式无法从文本框获取文本
- AngularJs 指令在更改时获取单选按钮 ng-model 值
- 使用getterSetter从ng-model中获取无限摘要循环
- AngularJS -无法从ng-model获取值到控制器
- Angular的ng-click无法获取ng-model的值
- 通过ng-repeat, ng-model和复选框获取数组中的位置
- 从控制器获取未定义的ng-model
- 从模板中获取ng-model值
- 如何将计算出的ng-model值获取到另一个ng-model中
- Angular JS:在ng-change上获取ng-model