如何调用组件的方法并从应用程序组件获取返回值

时间:2019-03-23 17:10:10

标签: angular angular-components

我需要访问从子组件返回的数据。假设<!-- Action to open list --> <act_window id="action_for_menu" name="List of products" res_model="x.x" view_type="form" view_mode="tree,form" /> <!-- List view. --> <record id="x_list_view" model="ir.ui.view"> <field name="name">x.list</field> <field name="model">x.x</field> <field name="arch" type="xml"> <tree> <field name="name"/> <field name="descr"/> </tree> </field> </record> getValue()中返回字符串的方法。我想调用该方法并在ChildComponent的{​​{1}}方法中获取值。

ChildComponent

AppComponent

AppComponent

doSomething()

@Component({ selector: 'child-component', templateUrl: './child.component.html', styleUrls: ['./child.component.scss'] }) export class ChildComponent { constructor() { } ngOnInit() { } getValue() { // get values from text editor (QuillJS editor) // do something with data // return value return value; } } 返回的值将根据编辑器(Quill JS文本编辑器)上的内容,光标位置,当前文本选择等而改变...我已经看到一些解决方案会从{{1 }}订阅者,以便订阅者可以保持最新状态,但是由于有太多因素推动着价值的改变,所以我认为这不是一个好方法。寻找适当的方式来处理此问题。

0 个答案:

没有答案