![](/img/trans.png)
[英]Bind to template of formly field on click of other field in angular formly
[英]Angular formly - Get model from field in wrapper
我正在创建一个包装器,该包装器将模型值在页面上显示为常规文本。 在此文本上触发鼠标悬停时,它将转换为一个正式字段,这很好用。 我的问题是,在字段中进行编辑后,普通文本不会更改,因此,如果可能的话,如何从字段中获取模型的值?
包装器:
template: [
'<div ng-hide="to.editorEnabled" >',
'<div ng-mouseover="to.editorEnabled=true">',
'{{to.label}}</br>',
'{{to.value}}',
'</div>',
'</div>',
'<div ng-show="to.editorEnabled" ng-mouseleave="to.editorEnabled=false">',
'<formly-transclude></formly-transclude>',
'</div>'
]
领域和型号:
vm.model = {textField: "Mouse over this field"};
vm.fields = [
{
key: 'textField',
type: 'input',
templateOptions: {
label: 'Text Label',
type: 'text',
value:vm.model.textField
}
}];
使用正式的观察者解决了问题。
观察者代码:
vm.fields = [
{
key: 'textField',
type: 'input',
templateOptions: {
label: 'Text Label',
type: 'text',
value:vm.model.textField
},
watcher: {
listener: function(field, newValue, oldValue, scope, stopWatching) {
if(newValue) {
field.templateOptions.value = newValue;
}
}
}
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.