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

Function form

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

Source from the content-addressed store, hash-verified

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