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

Function form

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

Source from the content-addressed store, hash-verified

223): FieldTree<TModel>;
224
225export function form<TModel>(...args: any[]): FieldTree<TModel> {
226 const [model, schema, options] = normalizeFormArgs<TModel>(args);
227 const injector = options?.injector ?? inject(Injector);
228 const pathNode = runInInjectionContext(injector, () => SchemaImpl.rootCompile(schema));
229 const fieldManager = new FormFieldManager(
230 injector,
231 options?.name,
232 options?.submission as FormSubmitOptions<unknown, unknown> | undefined,
233 );
234 const adapter = options?.adapter ?? new BasicFieldAdapter();
235 const fieldRoot = FieldNode.newRoot(fieldManager, model, pathNode, adapter);
236 fieldManager.createFieldManagementEffect(fieldRoot.structure);
237
238 // Register a WebMCP tool for the form if configured.
239 const {experimentalWebMcpTool} = options ?? {};
240 if (experimentalWebMcpTool) {
241 const registerWebMcpForm = runInInjectionContext(injector, () =>
242 inject(REGISTER_WEBMCP_FORM, {optional: true}),
243 );
244 if (registerWebMcpForm) {
245 runInInjectionContext(injector, () =>
246 registerWebMcpForm(fieldRoot.fieldTree, {
247 name: experimentalWebMcpTool.name,
248 description: experimentalWebMcpTool.description,
249 annotations: experimentalWebMcpTool.annotations,
250 }),
251 );
252 } else {
253 if (typeof ngDevMode !== 'undefined' && ngDevMode) {
254 throw new Error(
255 `Cannot register form "${experimentalWebMcpTool.name}" as a WebMCP tool. ` +
256 `Make sure to use \`provideExperimentalWebMcpForms()\` in your application bootstrap configuration.`,
257 );
258 }
259 }
260 }
261
262 return fieldRoot.fieldTree as FieldTree<TModel>;
263}
264
265/**
266 * 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
readonly.spec.tsFile · 0.90
hidden.spec.tsFile · 0.90

Calls 7

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

Tested by 4

testContextFunction · 0.68
createFormFunction · 0.68
createFormFunction · 0.68