我有一个角度分量
<my-component foo="" bar=""></my-component>
及其对应的类我的组件
我在我的 html 中使用这个组件
<my-component foo="bar" bar="foo"></my-component>
<my-component foo="baz" bar="qux"></my-component>
<my-component foo="bar" bar="baz"></my-component>
现在我想查询选择我的自定义元素并直接访问它们的属性。我想这样的事情:
List<MyComponent> mys = querySelector('my-component');
mys.forEach((my){
print(my.foo);
my.bar = '1234';
});
该代码存在 View 问题:
最佳答案
这不受官方支持。有类似 ng-element
的东西据我所知,这允许这样做,但仅用于单元测试。上一个版本有一些变化,但我不知道当前的状态。
您应该使用依赖注入(inject)、Angular 事件(在此处解释 How to communicate between Angular DART controllers)或访问其他元素的范围来传递引用。
关于jquery-selectors - querySelector 角度分量作为 Component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26264352/