MCPcopy
hub / github.com/angular/angular / form

Function form

packages/forms/signals/src/api/structure.ts:203–240  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

201): FieldTree<TModel>;
202
203export function form<TModel>(...args: any[]): FieldTree<TModel> {
204 const [model, schema, options] = normalizeFormArgs<TModel>(args);
205 const injector = options?.injector ?? inject(Injector);
206 const pathNode = runInInjectionContext(injector, () => SchemaImpl.rootCompile(schema));
207 const fieldManager = new FormFieldManager(
208 injector,
209 options?.name,
210 options?.submission as FormSubmitOptions<unknown, unknown> | undefined,
211 );
212 const adapter = options?.adapter ?? new BasicFieldAdapter();
213 const fieldRoot = FieldNode.newRoot(fieldManager, model, pathNode, adapter);
214 fieldManager.createFieldManagementEffect(fieldRoot.structure);
215
216 // Register a WebMCP tool for the form if configured.
217 const {experimentalWebMcpTool} = options ?? {};
218 if (experimentalWebMcpTool) {
219 const registerWebMcpForm = runInInjectionContext(injector, () =>
220 inject(REGISTER_WEBMCP_FORM, {optional: true}),
221 );
222 if (registerWebMcpForm) {
223 runInInjectionContext(injector, () =>
224 registerWebMcpForm(fieldRoot.fieldTree, {
225 name: experimentalWebMcpTool.name,
226 description: experimentalWebMcpTool.description,
227 }),
228 );
229 } else {
230 if (typeof ngDevMode !== 'undefined' && ngDevMode) {
231 throw new Error(
232 `Cannot register form "${experimentalWebMcpTool.name}" as a WebMCP tool. ` +
233 `Make sure to use \`provideExperimentalWebMcpForms()\` in your application bootstrap configuration.`,
234 );
235 }
236 }
237 }
238
239 return fieldRoot.fieldTree as FieldTree<TModel>;
240}
241
242/**
243 * Applies a schema to each item of an array.

Callers 15

TestCmpClass · 0.90
AppClass · 0.90
webmcp.spec.tsFile · 0.90
AppClass · 0.90
structure.spec.tsFile · 0.90
debounce.spec.tsFile · 0.90
hidden.spec.tsFile · 0.90
ApiReferenceListClass · 0.90

Calls 7

normalizeFormArgsFunction · 0.90
injectFunction · 0.90
runInInjectionContextFunction · 0.90
registerWebMcpFormFunction · 0.85
rootCompileMethod · 0.80
newRootMethod · 0.65

Tested by 2

testContextFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…