小编Joh*_*den的帖子

输入时没有表单标记的表单验证 - Angular 2

我有弹出组件,我想在输入元素上插入表单验证名称(必填字段和最小长度为3个字符).如果没有在表单标签中设置完整的代码,是否可以这样做?

<div class="scenario-div">
<label style="font-size: 1.4rem; font-weight: 400; margin-bottom: 10px;">{{context.header}}</label>
<div class="" style="width: 90%; margin-bottom: 10px; align-self: center;">
    <div style="display: flex; flex-direction: column; margin-bottom: 10px;">
        <label style="font-size: 1.2rem; font-weight: 500;">Name</label>
        <div style="display:flex; flex-direction:row;">
            <input type="text" [(ngModel)]="context.name" placeholder="enter Name" style="color: #569bd2; margin: 0px; width: 50%" minlength="3" required/>

            <select *ngIf="context.showOptionDropdown" class="custom-select-project" style="width:50%" #optionSelect (change)="context.option.value">
                <option disabled>Select type</option>
                <option value="option1">option1</option>
                <option value="option2">option2</option>
                <option value="option3">option3</option>
                <option value="option4">option4</option>
            </select>
        </div>
    </div>

    <div style="display: flex; flex-direction: column; margin-bottom: 10px;" *ngIf="!context.hideDescription">
        <label style="font-size: 1.2rem; font-weight: 400;">Description</label>
        <textarea …
Run Code Online (Sandbox Code Playgroud)

forms tags angular

2
推荐指数
1
解决办法
8146
查看次数

在 ngFor 中合并两个数组

我有两个从服务中获得的数组-a:

handleProjectLoaded(project){

    this.projectService.getCodesByType( "Structure" ).subscribe( response => {

        this.structures = response;
    });

    this.projectService.getCodesByType( "Direction" ).subscribe( response => {

        this.lines = response;
    });
}
Run Code Online (Sandbox Code Playgroud)

一个数组在结构中,第二个我在行中。我将它们分别放在 html 中并显示了 ngFor。

<div class="div-width-button3">
    <select #lineSelect class="custom-select custom-select-project" style="flex-basis:49%" (change)="addDirection(directionSelect.value); directionSelect.selectedIndex = 0;">
        <option selected disabled value="">Add a direction</option>
        <option *ngFor="let direction of directions" [value]=direction.id
            [selected]="direction.id==directionSelect.value">{{direction.name}}</option>
    </select> 
    <select #structureSelect class="custom-select custom-select-project"  style="flex-basis:49%"
        (change)="addStructure(structureSelect.value); structureSelect.selectedIndex = 0;">
        <option selected disabled value="">Add a structure</option>
        <option *ngFor="let structure of structures" [value]=structure.id
            [selected]="structure.id==structureSelect.value">{{structure.name}}</option>
    </select>
</div>
Run Code Online (Sandbox Code Playgroud)

我需要解决方案将这两个数组显示为一个带有一个 ngFor 的数组。有什么办法可以合并吗??

arrays merge angular

2
推荐指数
1
解决办法
2479
查看次数

Angular 2 - 将布尔值“true”从一个组件传递到另一个组件(不是兄弟组件)

在一个组件上,我有触发功能的按钮:

<button (click)="open Popup(); hideButton()"></button>
Run Code Online (Sandbox Code Playgroud)

我有,可以说:buttonService我应该用于这两个组件之间的连接。

在第二个组件(与第一个组件不相关的父子组件)中,我有多个这样的按钮:

<button class="element1"></button>
<button [class.hiddenClass]="hideButt" class="element2"></button>
<button class="element3"></button>
Run Code Online (Sandbox Code Playgroud)

第二个组件是弹出窗口,在第一个组件单击相同按钮时打开,此时它还应该触发hideButton()函数将布尔值“true”传递给hideButt并隐藏第二个(弹出)组件上的按钮。我该怎么做?与订阅,Observable,EventEmitter?

components boolean angular

2
推荐指数
1
解决办法
1万
查看次数

角度4-以45度为步长旋转图像

我有图像和两个按钮,应将图像旋转45或-45度。

<div>
    <img src="/assets/img1.png">
</div>
<div>
    <button type="submit">rotate left 45</button>
    <button type="submit">rotate right 45</button>
</div>
Run Code Online (Sandbox Code Playgroud)

如何使将CSS转换应用到此图像的函数?步骤应采用45度以太方式,并且无论用户单击按钮多少次,它都应不断旋转。

css image rotation degrees angular

2
推荐指数
1
解决办法
2210
查看次数

标签 统计

angular ×4

arrays ×1

boolean ×1

components ×1

css ×1

degrees ×1

forms ×1

image ×1

merge ×1

rotation ×1

tags ×1