Skip to content

Commit 3b41147

Browse files
committed
fix(app): support input models | first level of syntax support
fix #1474
1 parent 5d38edb commit 3b41147

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/app/compiler/angular/deps/helpers/component-helper.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,22 @@ export class ComponentHelper {
138138
public getInputSignals(props) {
139139
let inputSignals = [];
140140
props?.forEach((prop, i) => {
141-
const regexp = /input(?:\.(required))?(?:<([\w-]+)>)?\(([\w-]+)?\)/;
142-
const res = regexp.exec(prop.defaultValue);
143-
if (res) {
141+
const regexpInput = /input(?:\.(required))?(?:<([\w-]+)>)?\(([\w-]+)?\)/;
142+
const resInput = regexpInput.exec(prop.defaultValue);
143+
if (resInput) {
144144
const newInput = prop;
145-
newInput.defaultValue = res[res.length - 1];
146-
newInput.required = res[0]?.includes('.required') ?? false;
145+
newInput.defaultValue = resInput[resInput.length - 1];
146+
newInput.required = resInput[0]?.includes('.required') ?? false;
147147
inputSignals.push(newInput);
148+
} else {
149+
const regexpModel = /model(?:\.(required))?(?:<([\w-]+)>)?\(([\w-]+)?\)/;
150+
const resModel = regexpModel.exec(prop.defaultValue);
151+
if (resModel) {
152+
const newInput = prop;
153+
newInput.defaultValue = resModel[resModel.length - 1];
154+
newInput.required = resModel[0]?.includes('.required') ?? false;
155+
inputSignals.push(newInput);
156+
}
148157
}
149158
});
150159
return inputSignals;
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, model, input, Input, output } from '@angular/core';
22

33
/**
44
* The compodoc component
@@ -8,4 +8,26 @@ import { Component } from '@angular/core';
88
templateUrl: './compodoc.component.html',
99
styleUrl: './compodoc.component.css'
1010
})
11-
export class CompodocComponent {}
11+
export class CompodocComponent {
12+
// model input.
13+
checked = model(false);
14+
15+
// model input.
16+
checkedInf = model<string>();
17+
18+
// model input.
19+
checkedRequired = model.required<boolean>();
20+
21+
// standard input.
22+
disabled = input(false);
23+
24+
// optional input
25+
firstName = input<string>();
26+
27+
// required inputs
28+
lastName = input.required<string>();
29+
30+
buttonClick = output<MouseEvent>();
31+
32+
buttonClickSimple = output();
33+
}

test/src/cli/cli-generation-big-app.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,18 @@ describe('CLI simple generation - big app', () => {
974974
expect(file).to.contain('<div><i>&nbsp;Inputs</i> : color&nbsp;</div>');
975975
});
976976

977-
it('should support inputs and outputs signals', () => {
978-
const file = read(distFolder + '/classes/DumbParentComponent.html');
977+
it('should support inputs and outputs signals and model', () => {
978+
let file = read(distFolder + '/classes/DumbParentComponent.html');
979979
expect(file).to.contain('<a href="#label" >label</a>');
980980
expect(file).to.contain('<a href="#currentChange" >currentChange</a>');
981+
file = read(distFolder + '/components/CompodocComponent.html');
982+
expect(file).to.contain(`<h3 id="inputs">Inputs</h3>
983+
<table class="table table-sm table-bordered">
984+
<tbody>
985+
<tr>
986+
<td class="col-md-4">
987+
<a name="checked"></a>
988+
<b>checked</b>`);
981989
});
982990

983991
it('should support component styles url/urls', () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy