MCPcopy Create free account
hub / github.com/angular/angular / bind

Method bind

packages/compiler/src/render3/view/t2_binder.ts:183–282  ·  view source on GitHub ↗

* Perform a binding operation on the given `Target` and return a `BoundTarget` which contains * metadata about the types referenced in the template.

(target: Target<DirectiveT>)

Source from the content-addressed store, hash-verified

181 * metadata about the types referenced in the template.
182 */
183 bind(target: Target<DirectiveT>): BoundTarget<DirectiveT> {
184 if (!target.template && !target.host) {
185 throw new Error('Empty bound targets are not supported');
186 }
187
188 const directives: MatchedDirectives<DirectiveT> = new Map();
189 const foreignComponents = new Map<Element, ForeignComponentMeta>();
190 const eagerDirectives: DirectiveT[] = [];
191 const bindings: BindingsMap<DirectiveT> = new Map();
192 const references: ReferenceMap<DirectiveT> = new Map();
193 const scopedNodeEntities: ScopedNodeEntities = new Map();
194 const expressions = new Map<AST, TemplateEntity>();
195 const symbols = new Map<TemplateEntity, ScopedNode>();
196 const nestingLevel = new Map<ScopedNode, number>();
197 const usedPipes = new Set<string>();
198 const eagerPipes = new Set<string>();
199 const deferBlocks: DeferBlockScopes = [];
200 const pipes = new Map<BindingPipe, DeferredBlock[]>();
201 const conflictingHostDirectiveBindings = new Map<
202 DirectiveOwner,
203 ConflictingHostDirectiveBinding<DirectiveT>[]
204 >();
205
206 if (target.template) {
207 // First, parse the template into a `Scope` structure. This operation captures the syntactic
208 // scopes in the template and makes them available for later use.
209 const scope = Scope.apply(target.template);
210
211 // Next, perform directive matching on the template using the `DirectiveBinder`. This returns:
212 // - directives: Map of nodes (elements & ng-templates) to the directives on them.
213 // - bindings: Map of inputs, outputs, and attributes to the directive/element that claims
214 // them. TODO(alxhub): handle multiple directives claiming an input/output/etc.
215 // - references: Map of #references to their targets.
216 DirectiveBinder.apply(
217 target.template,
218 this.directiveMatcher,
219 this.foreignComponentMatcher,
220 directives,
221 foreignComponents,
222 eagerDirectives,
223 bindings,
224 references,
225 conflictingHostDirectiveBindings,
226 );
227
228 // Next, run the TemplateBinder to bind references, variables, and other entities within the
229 // template. This extracts all the metadata that doesn't depend on directive matching.
230 TemplateBinder.applyWithScope(
231 target.template,
232 scope,
233 expressions,
234 symbols,
235 nestingLevel,
236 usedPipes,
237 eagerPipes,
238 deferBlocks,
239 pipes,
240 );

Callers 9

parseJitTemplateFunction · 0.95
getBoundTemplateFunction · 0.95
tcbFunction · 0.95
indexMethod · 0.95
adaptTcbInputFunction · 0.95
compileClassesFunction · 0.95

Calls 4

applyWithScopeMethod · 0.80
applyMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected