本文整理匯總了TypeScript中@angular/core/src/view/index.asProviderData函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript asProviderData函數的具體用法?TypeScript asProviderData怎麽用?TypeScript asProviderData使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了asProviderData函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should query providers on the same element and child elements', () => {
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 5, 'div'),
...contentQueryProviders(1),
aServiceProvider(1 + cQPLength),
elementDef(2 + cQPLength, NodeFlags.None, null, null, 1, 'div'),
aServiceProvider(3 + cQPLength),
]));
const qs: QueryService = asProviderData(view, 1).instance;
expect(qs.a).toBeUndefined();
Services.checkAndUpdateView(view);
const as = qs.a.toArray();
expect(as.length).toBe(2);
expect(as[0]).toBe(asProviderData(view, 3).instance);
expect(as[1]).toBe(asProviderData(view, 5).instance);
});
示例2: it
it('should query the first match', () => {
class QueryService {
a: AService;
}
const {view} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 4, 'div'),
directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef(
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.First}),
aServiceProvider(),
aServiceProvider(),
]));
Services.checkAndUpdateView(view);
const qs: QueryService = asProviderData(view, 1).instance;
expect(qs.a).toBe(asProviderData(view, 3).instance);
});
示例3: it
it('should provide data for text nodes', () => {
const view = createViewWithData();
const compView = asProviderData(view, 1).componentView;
const debugCtx = Refs.createDebugContext(compView, 2);
expect(debugCtx.componentRenderElement).toBe(asElementData(view, 0).renderElement);
expect(debugCtx.renderNode).toBe(asTextData(compView, 2).renderText);
expect(debugCtx.injector.get(AComp)).toBe(compView.component);
expect(debugCtx.component).toBe(compView.component);
expect(debugCtx.context).toBe(compView.context);
expect(debugCtx.source).toBeTruthy();
});
示例4: it
it('should include projected nodes when attaching / detaching embedded views', () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef([textDef(0, ['a'])], [
elementDef(NodeFlags.None, null, null, 1, 'div'),
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, 0, embeddedViewDef([ngContentDef(null, 0)])),
])));
const componentView = asProviderData(view, 1).componentView;
const view0 = createEmbeddedView(componentView, componentView.def.nodes[1]);
attachEmbeddedView(asElementData(componentView, 1), 0, view0);
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0])).length).toBe(2);
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[1])
.toBe(asTextData(view, 2).renderText);
detachEmbeddedView(asElementData(componentView, 1), 0);
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0])).length).toBe(1);
});
示例5: it
it('should query ViewContainerRef', () => {
class QueryService {
a: ViewContainerRef;
}
const {view} = createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.None, [[someQueryId, QueryValueType.ViewContainerRef]], null, 2),
directiveDef(NodeFlags.None, null, 1, QueryService, []),
queryDef(
NodeFlags.HasContentQuery | NodeFlags.HasDynamicQuery, someQueryId,
{'a': QueryBindingType.First}),
]));
Services.checkAndUpdateView(view);
const qs: QueryService = asProviderData(view, 1).instance;
expect(qs.a.createEmbeddedView).toBeTruthy();
});