本文整理汇总了TypeScript中@angular/core/src/view/index.directiveDef函数的典型用法代码示例。如果您正苦于以下问题:TypeScript directiveDef函数的具体用法?TypeScript directiveDef怎么用?TypeScript directiveDef使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了directiveDef函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should calculate childMatchedQueries for one level, multiple roots', () => {
const vd = viewDef(ViewFlags.None, [
elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 0, AService, []),
elementDef(NodeFlags.None, null, null, 2, 'span'),
directiveDef(NodeFlags.None, [['q2', QueryValueType.Provider]], 0, AService, []),
directiveDef(NodeFlags.None, [['q3', QueryValueType.Provider]], 0, AService, []),
]);
expect(childMatchedQueries(vd)).toEqual([['q1'], [], ['q2', 'q3'], [], []]);
});
示例2: it
it('should calculate childMatchedQueries for one level, multiple roots', () => {
const vd = viewDef(ViewFlags.None, [
elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.None, [[1, QueryValueType.Provider]], 0, AService, []),
elementDef(NodeFlags.None, null, null, 2, 'span'),
directiveDef(NodeFlags.None, [[2, QueryValueType.Provider]], 0, AService, []),
directiveDef(NodeFlags.None, [[3, QueryValueType.Provider]], 0, AService, []),
]);
expect(childMatchedQueries(vd)).toEqual([
filterQueryId(1), 0, filterQueryId(2) | filterQueryId(3), 0, 0
]);
});
示例3: it
it('should calculate childFlags for one level, multiple roots', () => {
const vd = viewDef(ViewFlags.None, [
elementDef(NodeFlags.None, null, null, 1, 'span'),
directiveDef(NodeFlags.AfterContentChecked, null, 0, AService, []),
elementDef(NodeFlags.None, null, null, 2, 'span'),
directiveDef(NodeFlags.AfterContentInit, null, 0, AService, []),
directiveDef(NodeFlags.AfterViewChecked, null, 0, AService, []),
]);
expect(childFlags(vd)).toEqual([
NodeFlags.AfterContentChecked, NodeFlags.None,
NodeFlags.AfterContentInit | NodeFlags.AfterViewChecked, NodeFlags.None, NodeFlags.None
]);
});
示例4: it
it('should query all matches', () => {
class QueryService {
// TODO(issue/24571): remove '!'.
a !: QueryList<AService>;
}
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 4, 'div'),
directiveDef(1, NodeFlags.None, null, 1, QueryService, []),
queryDef(
NodeFlags.TypeContentQuery | NodeFlags.DynamicQuery, someQueryId,
{'a': QueryBindingType.All}),
aServiceProvider(3),
aServiceProvider(4),
]));
Services.checkAndUpdateView(view);
const qs: QueryService = asProviderData(view, 1).instance;
expect(qs.a instanceof QueryList).toBeTruthy();
expect(qs.a.toArray()).toEqual([
asProviderData(view, 3).instance,
asProviderData(view, 4).instance,
]);
});
示例5: it
it('should not stop dirty checking views that threw errors in change detection', () => {
class AComp {
a: any;
}
const update = jasmine.createSpy('updater');
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
() => compViewDef(
[elementDef(
0, NodeFlags.None, null, null, 0, 'span', null,
[[BindingFlags.TypeElementAttribute, 'a', SecurityContext.NONE]])],
null, update)),
directiveDef(1, NodeFlags.Component, null, 0, AComp, [], null, null, ),
]));
update.and.callFake((check: NodeCheckFn, view: ViewData) => { throw new Error('Test'); });
expect(() => Services.checkAndUpdateView(view)).toThrowError('Test');
expect(update).toHaveBeenCalled();
update.calls.reset();
expect(() => Services.checkAndUpdateView(view)).toThrowError('Test');
expect(update).toHaveBeenCalled();
});
示例6: createAndGetRootNodes
() => {
class AComp {
a: any;
}
const update = jasmine.createSpy('updater');
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(NodeFlags.None, null, null, 1, 'div', null, null, null, null, () => compViewDef(
[
elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
],
null, update)),
directiveDef(
NodeFlags.IsComponent, null, 0, AComp, [], null, null,
),
]));
const compView = asElementData(view, 0).componentView;
update.and.callFake(
(check: NodeCheckFn, view: ViewData) => { throw new Error('Test'); });
expect(() => Services.checkAndUpdateView(view)).toThrowError('Test');
expect(update).toHaveBeenCalled();
update.calls.reset();
Services.checkAndUpdateView(view);
expect(update).not.toHaveBeenCalled();
});
示例7: it
it(`should support ${ArgumentType[inlineDynamic]} bindings`, () => {
let values: any[];
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
[
elementDef(NodeFlags.None, null, null, 2, 'span'), pureArrayDef(2),
directiveDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
],
(check, view) => {
const pureValue = checkNodeInlineOrDynamic(check, view, 1, inlineDynamic, values);
checkNodeInlineOrDynamic(check, view, 2, inlineDynamic, [pureValue]);
}));
const service = asProviderData(view, 2).instance;
values = [1, 2];
Services.checkAndUpdateView(view);
const arr0 = service.data;
expect(arr0).toEqual([1, 2]);
// instance should not change
// if the values don't change
Services.checkAndUpdateView(view);
expect(service.data).toBe(arr0);
values = [3, 2];
Services.checkAndUpdateView(view);
const arr1 = service.data;
expect(arr1).not.toBe(arr0);
expect(arr1).toEqual([3, 2]);
});
示例8: it
it('report the binding name when an expression changes after it has been checked', () => {
let value: any;
class AComp {}
const update =
jasmine.createSpy('updater').and.callFake((check: NodeCheckFn, view: ViewData) => {
check(view, 0, ArgumentType.Inline, 'const', 'const', value);
});
const {view, rootNodes} = createAndGetRootNodes(
compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, () => compViewDef([
elementDef(0, NodeFlags.None, null, null, 0, 'span', null, [
[BindingFlags.TypeElementAttribute, 'p1', SecurityContext.NONE],
[BindingFlags.TypeElementAttribute, 'p2', SecurityContext.NONE],
[BindingFlags.TypeElementAttribute, 'p3', SecurityContext.NONE],
]),
], null, update)
),
directiveDef(1, NodeFlags.Component, null, 0, AComp, []),
]));
value = 'v1';
Services.checkAndUpdateView(view);
value = 'v2';
expect(() => Services.checkNoChangesView(view))
.toThrowError(
`ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'p3: v1'. Current value: 'p3: v2'.`);
});
示例9: it
it('should project already attached embedded views', () => {
class CreateViewService {
constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
viewContainerRef.createEmbeddedView(templateRef);
}
}
const {view, rootNodes} =
createAndGetRootNodes(
compViewDef(
hostElDef(0,
[
anchorDef(
NodeFlags.EmbeddedViews, null, 0, 1, null,
compViewDefFactory([textDef(0, null, ['a'])])),
directiveDef(3,
NodeFlags.None, null, 0, CreateViewService,
[TemplateRef, ViewContainerRef]),
],
[
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
ngContentDef(null, 0),
])));
const anchor = asElementData(view, 2);
expect((getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[0]))
.toBe(anchor.renderElement);
const embeddedView = anchor.viewContainer !._embeddedViews[0];
expect((getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[1]))
.toBe(asTextData(embeddedView, 0).renderText);
});