标签: angular6

如何从.net core 2.1 Angular 6模板中的非相对路径导入ts和scss文件

我已经创建了一个新的.net core 2.1应用程序angular template,之后我更新了要使用的项目Angular 6.

请注意,该项目与angular cli生成的项目几乎相同

我的项目将有很多组件和服务,因此我不想使用相对路径,而是希望能够使用非相对路径

打字稿

import { WeatherService } from '../../services/weather.service'
Run Code Online (Sandbox Code Playgroud)

我希望能够使用非相对路径,如:

import { WeatherService } from '@app-services/weather.service'
Run Code Online (Sandbox Code Playgroud)

所以我补充道

"baseUrl": ".",
    "paths": {
      "@app-services/*": [ "src/app/services/*" ]
    },
Run Code Online (Sandbox Code Playgroud)

进入 tsconfig.json

整个配置:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "baseUrl": ".",
    "paths": {
      "@app-services/*": [ "src/app/services/*" ]
    },
    "lib": [
      "es2017",
      "dom"
    ]
  }
} …
Run Code Online (Sandbox Code Playgroud)

path sass typescript visual-studio-2017 angular6

6
推荐指数
1
解决办法
780
查看次数

angular 6中所有angular.json选项是什么?

Angular-CLI文档似乎没有包含对angular.json模式的完整引用,是否有地方可以找到可用选项的更完整列表?

angular angular6 angular-cli-v6

6
推荐指数
1
解决办法
4806
查看次数

Angular 6文件与其他表单数据一起上传

我已输入数据用户详细信息first_name,last_name,phone_number和profile_pic但文件未上传其他表单数据如何上传其他表单数据文件?

用户form.component.ts

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { UserService } from '../user.service';
import { FileUploader, FileSelectDirective } from 'ng2-file-upload/ng2-file-upload';

@Component({
  selector: 'user-form',
  templateUrl: './user-form.component.html',
  styleUrls: ['./user-form.component.scss']
})
export class UserFormComponent {
  angForm: FormGroup
  router: Router;

  constructor(private userservice: UserService, private fb: FormBuilder, private _route: Router) {
    this.createForm();
    this.router = _route;
  }

  createForm() {
    this.angForm = this.fb.group({
      first_name: ['', …
Run Code Online (Sandbox Code Playgroud)

angular6

6
推荐指数
1
解决办法
4729
查看次数

如何为Angular 6项目定义高度可扩展的文件夹结构?

我正在学习更多关于角度6及其核心功能的内容,我对于应该使用角度6的文件夹结构感到困惑,我使用了不同教程的不同结构,例如traversymedia,udemy和list继续,每个人都使用不同的文件夹结构取决于项目.

这是angular docs的基本文件夹结构 在此输入图像描述

这是我搜索和搜索后尝试过的内容

????src
    ????app
    ?   ????layout
    ?   ?   ????admin
    ?   ?   ?   ????breadcrumbs
    ?   ?   ?   ????title
    ?   ?   ????auth
    ?   ????pages
    ?   ?   ????animations
    ?   ?   ????authentication
    ?   ?   ?   ????forgot
    ?   ?   ?   ????lock-screen
    ?   ?   ?   ????login
    ?   ?   ?   ?   ????with-bg-image
    ?   ?   ?   ?   ????with-header-footer
    ?   ?   ?   ?   ????with-social
    ?   ?   ?   ?   ????with-social-header-footer
    ?   ?   ?   ????registration
    ?   ?   ?       ????multi-step
    ?   ?   ?       ????with-bg-image
    ?   ?   ?       ????with-header-footer
    ?   ? …
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

6
推荐指数
1
解决办法
5347
查看次数

来自Angular的非XHR(非AJAX)发布请求

在Angular应用程序中使用外部服务是一项要求。外部服务具有自己的用户界面。因此,我们必须使用给定外部服务URL上的纯HTTP Post请求重定向到外部服务。

有没有一种方法可以从Angular进行非AJAX后期调用,以便屏幕重定向到外部服务网页。

angular angular6

6
推荐指数
1
解决办法
575
查看次数

角度材质选项卡将图像添加到按钮

我是Angular的初学者.我尝试用Angular材料选项卡做一些事情.我将标签部分添加到图像,但该部分无效.有谁知道如何将图像添加到角度材料选项卡.请查看我的附图,了解我尝试实现的目标.

需要这样的

我的代码到目前为止(stackblitz demo)

我的代码部分:

<mat-tab-group mat-stretch-tabs class="example-stretched-tabs mat-elevation-z4">
  <mat-tab label="First"  style="background:url('/assets/img/school-01.png')"> Content 1 </mat-tab>
  <mat-tab label="Second"> Content 2 </mat-tab>
  <mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)

CSS

.example-stretched-tabs {
  max-width: 800px;
}
/* active tab */
.mat-tab-list .mat-tab-labels .mat-tab-label-active {
  color:#0f2241;
  background-color: #535353;
  opacity: 1;
}

/* ink bar */
.mat-tab-group.mat-primary .mat-ink-bar {
  background: none;
  content: url('https://image.flaticon.com/icons/svg/60/60995.svg');
  height: 10px; 
}
Run Code Online (Sandbox Code Playgroud)

.TS

import {Component, ViewEncapsulation} from '@angular/core';

/**
 * @title Tab group with stretched labels
 */
@Component({
  selector: 'tab-group-stretched-example',
  templateUrl: 'tab-group-stretched-example.html',
  styleUrls: …
Run Code Online (Sandbox Code Playgroud)

tabs angular-material angular angular6

6
推荐指数
1
解决办法
7638
查看次数

使用角度6中的反应形式的递归形式(树视图)

我从下面了解递归元素(树视图)的概念.

链接1

在我的情况下,我想用它与表格; 让我们说递归的简单文本输入.表单的JSON结构如下.

JOSN结构

我准备下面的代码.我通过执行下面的代码得到最大调用堆栈大小超过错误.

下面是我的component.html文件.

<form [formGroup]="testForm" (ngSubmit)="onSubmit()">
    <div formArrayName="element">
        <ng-template #recursiveList let-list>       
              <div *ngFor="let item of testForm.get('element').controls;let i=index;">     
                  <div [formGroupName]="i">
                    <input type="text" formControlName="type">
                  </div> 
                  <!-- {{item.get('element')?.controls?.length}} -->
                  <div *ngIf="item.get('element')?.controls?.length > 0">          
                    <ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: item.get('element').controls }"></ng-container>
                  </div>
              </div>          
        </ng-template>
        <ng-container *ngTemplateOutlet="recursiveList; context:{ $implicit: testForm.get('element').controls }"></ng-container>
    </div>     
Run Code Online (Sandbox Code Playgroud)

这是component.ts文件.

import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, Validators, FormBuilder, FormArray} from '@angular/forms';

@Component({
    selector: 'app-test',
    templateUrl: './test.component.html',
    styleUrls: [
      './test.component.scss' …
Run Code Online (Sandbox Code Playgroud)

angular angular6

6
推荐指数
1
解决办法
1679
查看次数

Angular 6验证数字输入

我有一个输入,类型是数字。我要设置最小值和最大值,如果输入超出此范围(<最小值或>最大值),将显示错误。

我的问题是,如果输入不是空但无效,则错误消失(例如:min = 10,max = 20,input = 2000,仍然没有错误显示)。

我在此站点上搜索,并且有关于验证的帖子,但是解决方案是使用<md-input-container>和<md-error>。我不想使用<md-input-container>和<md-error>。

参考:这里

反正有解决我的问题的方法吗?

我的add-hero.component.html:

<div class="publishedYear">
<label>Publish Year: </label>
<input type="number" id="PublishedYear" name="PublishedYear" required min="10" max="20" 
[(ngModel)]="hero.PublishedYear" #publishedYear="ngModel">
<p class="alert alert-danger invalid" *ngIf="publishedYear.errors">Invalid Published Year</p>
</div>
Run Code Online (Sandbox Code Playgroud)

我的英雄

export class Hero {
Id: number;
Name: string;
PublishedYear: number;
Complete?: boolean;
}
Run Code Online (Sandbox Code Playgroud)

angular angular6

6
推荐指数
4
解决办法
3万
查看次数

角6或7:如何在'@ angular / common / http'中导入RequestOptions和ResponseContentType

我已将4号角代码迁移到6号角,我想知道如何在6号或7号角下面导入代码?

import { RequestOptions, ResponseContentType } from '@angular/common/http';
Run Code Online (Sandbox Code Playgroud)

angular angular6 angular7

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

从Java HashMap显示Angular下拉列表

我想使用Spring Application的GET请求在Angular应用程序中显示HashMap.我试过这个:

春天代码:

@GetMapping("gateways")
public ResponseEntity<?> getGateways() {
    Map<Integer, String> list = new HashMap<>();
    list.put(1, "Bogus");
    return ok(list.put);
}
Run Code Online (Sandbox Code Playgroud)

角度服务:

getContractGatewaysList(): Observable<Array<ContractGatewaysList>> {
    return this.http.get<Array<ContractGatewaysList>>(environment.api.urls.contracts.getContractGateways);
  }
Run Code Online (Sandbox Code Playgroud)

角度成分:

gateways: ContractGatewaysList[];

this.contractService.getContractGatewaysList()
      .subscribe(value => {
        if (value != null) {
          this.gateways = value;
        }
      });
Run Code Online (Sandbox Code Playgroud)

接口:

export interface ContractGatewaysList {
  id: number;
  name: string;
}
Run Code Online (Sandbox Code Playgroud)

HTML代码:

<div class="form-group gateway">
    <div class="input-group-prepend">
      <label for="merchant_id">Gateway</label>
    </div>
    <select class="custom-select" name="gateway" [(ngModel)]="contract.gateway" id="gateway" required>
      <option selected>Please Select...</option>
      <option [value]="gateway.id" *ngFor="let gateway of gateways">{{ gateway.name }}</option>
    </select> …
Run Code Online (Sandbox Code Playgroud)

spring typescript angular angular6

6
推荐指数
1
解决办法
1224
查看次数