使用表达式属性访问不同的模型模板选项
Using ExpressionProperties to access different model templateOptions
首先,我想说Angular Formly对于像我这样的新手来说是一个很棒的库。我不是 Web 开发人员,但是发现这个库直观且功能强大。
但是,我确实需要有关使用表达式属性的帮助。
我有一个包含库项目的模型库,例如:
{
"itemId":"STX001",
"title":"Grey Wolf",
"category":"White", etc.
}
{
"itemId":"STX002",
"title":"Noble Black",
"category":"Black", etc.
}
etc.
我还有一个表单,它使用 top 字段中的 ui-select
从库中查找所有值,选择其中一个(我称之为Item
),然后用 Items
属性填充表单中的其余字段,然后将表单提交到Catalogue
模型。
面临的问题是我无法从其他字段中引用Item
的属性。我尝试使用expressionProperties
但只能提取valueProp
值(这是唯一ID),但是我在Item.title,Item.category等之后。
代码如下:
{
//This is form fields for creating a new Catalogue entry
key: 'libraryId',
type: 'ui-select',
templateOptions: {
label: gettextCatalog.getString('Search Library'),
options: [],
valueProp: 'itemId',
itemTitle: 'title',
itemCategory: 'category',
labelProp: 'title',
focus: true,
placeholder: 'Start typing keywords..'
},
controller: function ($scope) {
getLibrary().then(function(data){
$scope.options.templateOptions.options = data;
return data;
});
}
}
{
key: 'title',
type: 'input',
templateOptions: {
label: gettextCatalog.getString('Name'),
required: true
},
expressionProperties : {
//This is what i'm trying to achieve but doesn't work
'templateOptions.placeholder' : 'model.libraryId.itemTitle'
}
},
使用提供的回调函数
expressionPropertyObj = {
'templateOptions.required': (model, formState: any, field: FormlyFieldConfig) => {
console.log('model',model);
console.log('state',formState);
console.log('field',field);
},
相关文章:
- 如何将ng选项的索引作为angularJs中的值传递给模型
- 角度去抖动(ng模型选项)不起作用
- 选择框中带有关联的ng模型,选项中带有ng重复
- AngularJS模型在手动更改选项后不会更新
- 为什么ng选项指令需要ng模型
- 为什么ng模型重置所选选项
- 选择与ng模型和ng选项绑定时不进行选择
- angular 1.3中的ng选项在集合异步设置时忘记了ng模型
- 如何在Angularjs中使用ng选项时更新ng模型
- Select选项包含在验证模型MVC时不起作用
- 如何根据已知的ng选项和标准设置ng模型
- 所选选项更改时,模型不会更新
- 如何将类模型与 Redux 一起使用(带有 Mobx 选项)
- 使用表达式属性访问不同的模型模板选项
- 为什么当我将数据选项添加到骨干模型获取时,它不会触发回调
- NG 模型未绑定在选择元素中的 NG 重复选项上
- 使用 ng 模型有条件地过滤 ng 选项
- 如何使用轨迹选项进行选择,以角度保存模型中的选定对象
- 为简单数组提供带有 ng 选项的模型索引
- 模型选项的目的是什么?