标签: angular8

如何以角度模板驱动形式使用垫自动选择设置过滤器

如何以角度模板驱动形式使用垫自动选择来设置过滤器。

<mat-form-field class="pl">
    <input matInput name="item_id" 
    [(ngModel)]="stock.item_id" 
    #item_id="ngModel" 
    placeholder="Item"           
    [matAutocomplete]="auto" required>
    <mat-autocomplete #auto="matAutocomplete" [displayWith]="valueMapper">
        <mat-option *ngFor="let item of itemsData" [value]="item.id">
        {{item.text}}
        </mat-option>
    </mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

请参阅 stackblitz 示例:单击此处

angular mat-autocomplete angular8

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

Angular8 cdk:拖放不适用于网格

我尝试在单行中使用 CDK 拖放,它工作得很好,同样,它对于单列也工作得很好,但当我使用flex-wrap: wrap在行和列中显示图块时,它无法正常工作。

这是一个演示 https://stackblitz.com/edit/angular-etbue5

html javascript drag-and-drop angular angular8

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

Angular:格式化时刻以在 html 中显示为日期

我在 Angular 中有一个 Moment 类型的数据类型,每次它在 Angular 中显示时,它都会显示为

<div>{{dateStart}}</div>

Fri Mar 08 2019 20:24:35 GMT-0800
Run Code Online (Sandbox Code Playgroud)

如何显示“3/8/2019”?

如果在 Typescript 中进行转换,我们必须采用现有的类,并使用最后两种数据类型作为日期重新创建新类。只是好奇 HTML 或 Pipe 函数中是否有 Displayformat Angular?在哪里转换成HTML?

export class Address {
    fullName: string;
    mailingAddress: string;
    phoneNumber: string;
    emailAddress: string;
    dateStart?: moment.Moment;
    dateEnd?: moment.Moment;
Run Code Online (Sandbox Code Playgroud)

资源问题:

Angular:格式化时刻以在 html 中显示为日期

使用 moment.js 将字符串转换为日期

如何在角度时刻选择器中将今天的日期和时间设置为默认值

javascript typescript angular angular8

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

根 URL www.domain.com 的元标记不会更新

我正在创建一个部署在 firebase 上的 Angular8 通用应用程序。引用了这个网站Angular universal with firebase

当我在本地使用 Express 服务器运行并提供应用程序时,所有路由都将加载更新的元标记。当我在 firebase 上部署应用程序时,一切正常,但根路径上的元标记没有更新。它们对于所有其他路线都工作得非常好。当我打开检查元素时,元标记也会更新。我添加了一些配置,以便不在 firebase.json How to Prevent caching for the index.html of an SPA上缓存 html 文件,并将 server.ts 文件中的“cache”值设置为“No-cache”,如下所示

app.get('*', (req, res) => {
  res.set('Cache-Control', 'public, max-age=0, s-maxage=0, no-cache');
  res.render('index', { req });
});
Run Code Online (Sandbox Code Playgroud)

但对我来说没有任何作用。请帮忙。

firebase-hosting google-cloud-functions angular-universal angular angular8

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

Angular 8 中的差异加载如何管理两个独立包的大小?

差异加载是一种策略,其中 CLI 构建两个单独的包作为已部署应用程序的一部分。

Angular CLI 版本 8 及更高版本默认支持差异加载。对于工作区中的每个应用程序项目,您可以根据应用程序项目中的 browserslist 和 tsconfig.json 文件配置如何生成构建。

如果我们有两个具有差异加载功能的独立捆绑包,是否会导致构建大小问题和应用程序性能?

请分享您的建议,以便我可以在我当前的项目中选择此功能。

angular angular8

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

如何更改 Angular 后端的基本 url?

我有路径让路径="/";

当它调用这个路径时,Angular 会生成这样的路径:

http://localhost:4200/backend/api
Run Code Online (Sandbox Code Playgroud)

但是我需要

http://localhost/backend/api
Run Code Online (Sandbox Code Playgroud)

没有端口,如何在 Angular 中设置此选项?

angular angular5 angular8

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

如何在 Angular 8 中将登录用户数据存储在本地存储中

我想将登录用户数据存储在角度8的本地存储中,并获取该用户的数据。在此,我没有使用 Firebase 身份验证服务。

这是我的登录代码

login(empId: string, password: string){
  return this.af.database.ref('Users/' +empId).once('value').then(
    snap =>{
      var userPassword = (snap.val() && snap.val().password)
      if(password == userPassword){
       // this.router.navigate(['dashboard']);
      }
      else{
        console.log("Incorrect Password")
      }
    }
  )
}
Run Code Online (Sandbox Code Playgroud)

firebase-realtime-database angular angular8

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

当我们在服务中使用ngOnInit时?

当我们在服务中使用ngOnInit时?

例如,我需要监听服务内的观察者:

this.eventService.subscribe((data) => {

});
Run Code Online (Sandbox Code Playgroud)

将此代码放在构造函数或 ngOnInit 中哪里更好?

angular angular6 angular8

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

如何使用 ControlValueAccessor 在 Angular 8 中默认选择 mat-button-toggle

我正在尝试使用 Angulars ControlValueAccessor 创建自定义元素。目标是具有三种状态的开关:真、假和空。默认情况下应选择 Null,我尝试了其他帖子中的一些解决方案,但它们不起作用。
我尝试在 mat-button-toggle-group 中添加“value=null”,并在 null mat-button-toggle 本身中添加“checked”属性。

HTML:

<div class="nullableBoolWrapper" fxLayout="row">
<mat-label class="centred-vertically">{{ label }}</mat-label>
<mat-button-toggle-group class="selection-button"
[disabled]="isDisabled"
[(ngModel)]="selectedValue"
(change)="changed($event)">
    <mat-button-toggle ngDefaultControl value=true>{{ descriptionList[0].description }}</mat-button-toggle>
    <mat-button-toggle ngDefaultControl value=false>{{ descriptionList[1].description }}</mat-button-toggle>
    <mat-button-toggle ngDefaultControl value=null [disabled]="!selectableNull">{{ descriptionList[2].description }}</mat-button-toggle>
</mat-button-toggle-group>
Run Code Online (Sandbox Code Playgroud)

TS:

import { Description } from './../core/models/description';
import { Component, ViewEncapsulation, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

export const NULLABLE_BOOL_VALUE_ACCESSOR: any = {
  provide: NG_VALUE_ACCESSOR,
  useExisting: forwardRef(() => NullableBoolComponent),
  multi: true
}; …
Run Code Online (Sandbox Code Playgroud)

angular-material angular controlvalueaccessor angular8

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

Highlight specific words in textarea angular 8

I am trying to select a few words from the textarea and create bootstrap chips.

在此处输入图片说明

I am able to create the chips for selected words. I am trying to highlight the selected words with different background colors.

export class SearchComponent implements OnInit {

  constructor() { }

  selectedText = [];
  regexFromMyArray: RegExp;

  // tslint:disable-next-line:typedef
  showSelectedText() {
    let text = '';
    if (window.getSelection) {
      text = window.getSelection().toString();
      if (text) {
        // console.log(this.selectedText.includes(text));
        if (this.selectedText.includes(text) === false)
        {
          this.selectedText.push(text);
          this.regexFromMyArray = new RegExp(this.selectedText.join('|'), …
Run Code Online (Sandbox Code Playgroud)

javascript textarea angular angular8

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