我正在按照一个有角度的2课程,教师导航到他想要生成组件的特定路径,然后运行以下命令:
ng generate component component-name
Run Code Online (Sandbox Code Playgroud)
在运行它之后,该工具会生成当前目录中的文件,但是当我尝试相同时,该工具最终会在app根文件夹中生成文件.
换句话说,如果我这样做:
app\my-component> ng generate component component-name
Run Code Online (Sandbox Code Playgroud)
我希望命令在这里生成文件:
app\my-component\component-name\
component-name.component.html
component-name.component.ts
...
Run Code Online (Sandbox Code Playgroud)
而是在这里做:
app\component-name\
component-name.component.html
component-name.component.ts
...
Run Code Online (Sandbox Code Playgroud)
如何告诉ng-cli使用当前路径?
只有在满足某些条件时,我才需要在表单字段上应用验证.说我有这样的表格:
<div ng-controller="MyController">
<form name="myForm">
<div>
<div class="" ng-class="{error: myForm.gender.$invalid}">
Gender:
</div>
Male <input type="radio" name="gender" value="M" ng-model="survey.gender" required/>
Female <input type="radio" name="gender" value="F" ng-model="survey.gender" required/>
</div>
<div ng-show="survey.gender == 'F'">
<div class="">
Are you pregnant?
</div>
Yes <input type="radio" name="pregnant" value="Y" ng-model="survey.pregnant"/>
No <input type="radio" name="pregnant" value="N" ng-model="survey.pregnant"/>
</div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
我想只在用户选择女性时才提出怀疑问题.Angular会为此提供任何类型的验证吗?
我需要在包含符合特定条件的数据的行的顶部添加特定控件。这些标准缺少需要使用内联编辑功能添加的必需信息。我们想要的是一个导航控件,它位于第一个匹配行的顶部,并通过单击“下一步”将您带到下一个,这将使网格向上滚动到下一个匹配行,该行将在顶部显示另一个控件及以上允许导航到下一个匹配行或转到上一行。
假设我们有一个汽车列表,并且我们希望用户浏览价格低于或等于 45k 的汽车行,您将看到如下内容:
在下一次单击时,您将看到如下内容:
我相信为了拥有此功能,我需要对行进行引用,并在单击时相对于每一行在 DOM 中注入一个组件。但我不知道该怎么做。我尝试将组件动态添加到第一个匹配行的本机元素,如下所示:
onGridReady(params) {
this.api = params.api;
this.columnApi = params.columnApi;
params.api.forEachNode((node, index) => {
if(node.data.price <= 45000) {
this.matchingIndexes.push(index);
}
});
let firstRowRef = this.gridElementRef.nativeElement.querySelectorAll(`[row-index="${this.matchingIndexes[0]}"]`)[1];
const factory = this.factoryResolver.resolveComponentFactory(PagingOverlayComponent)
const component = factory.create(firstRowRef.parentInjector)
this.viewContainerRef.insert(component.hostView);
}
Run Code Online (Sandbox Code Playgroud)
我希望能够以某种方式相对于它必须附加的行插入组件,以便我可以将它放置在它上面。这是我能走的最远的地方:
关于如何实现这一目标的任何想法?