标签: angular6

在 ionic 4 中设置渐变背景

我只想为几页添加渐变背景,

登录页面.html

<ion-header>

</ion-header>

<ion-content padding class="bg-class">
   <p>lorem</p>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

_login.page.css

.bg-class{
    background-image: linear-gradient(197deg, rgba(100,100,100,1) 0%, rgba(63,63,63,1) 13.5%, rgba(29,29,29,1) 33.33%, rgba(0,0,0,1) 100%) !important
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,我能知道我哪里出错了吗?我还需要做些什么才能使这个工作正常进行。

ionic-framework angular ionic4 angular6

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

如何将类注入服务 [Angular 6]

我们可以将一个类(不是服务)作为共享实用程序,它可以通过角度依赖注入注入到服务甚至组件中吗?

我的实用类

export class MyUtilClass{

  do(){
     // something
  }
}
Run Code Online (Sandbox Code Playgroud)

我的服务

export class MyService{
  constructor(private uitl:MyUtilClass){
    util.do();
  }
}
Run Code Online (Sandbox Code Playgroud)

typescript angular angular6

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

Angular 6 Material - 等待 Mat Dialog 关闭

我有一个要完成的操作列表,如果设置了布尔值 promptRequired,我会显示一个对话框并根据它的值执行一些操作。

这里的问题是 for 循环并行运行并且所有操作同时执行,但我希望 for 循环同步运行并且循环必须等到对话框关闭。有解决办法吗?

async runActions() {
 for (const action of Actions) {
      if(action.promptRequired) {
      const dialogRef = this.promptDialog.open(PromptDialogComponent, {
        data: {action: action,
        },
      });
      // await dialogRef.afterClosed();
     }
    }

     const status =  await this.httpService.getRequest('runAction', action)
     // Do Some Action based on status
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

asynchronous async-await angular-material angular angular6

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

Angular 6 - angular.json - 通过重命名复制资产

我正在尝试在 ng build 的资产副本期间重命名文件

这是我在angular.json:

        "outputPath": "dist",
        "assets": [
          ...,
          {
            "glob": "favicon-v1.png",
            "input": "src/client",
            "output": "/favicon.png"
          },
          ...,
        ],
Run Code Online (Sandbox Code Playgroud)

不是创建文件dist/favicon.png,ng build而是创建一个dist/favicon.png/favicon-v1.png.

它似乎拒绝重命名文件 - 它总是使用我想使用的名称创建一个文件夹,favicon.png然后将原始文件放入其中。

这是预期的行为吗?任何不是文件重命名解决办法等favicon-v1.png,以favicong.png在源头控制?

我在用:

    "@angular/cli": "^6.1.5"

    "@angular/animations": "^6.0.1",
    "@angular/common": "^6.0.1",
    "@angular/compiler": "^6.0.1",
    "@angular/core": "^6.0.1",
    "@angular/forms": "^6.0.1",
    "@angular/http": "^6.0.1",
    "@angular/platform-browser": "^6.0.1",
    "@angular/platform-browser-dynamic": "^6.0.1",
    "@angular/router": "^6.0.1",
    "@angular/upgrade": "^6.0.1",
Run Code Online (Sandbox Code Playgroud)

更新:类似的代码在 Angular 5 中与 angular-cli.json 一起工作正常。

angular ng-packagr angular6

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

从另一个组件控制角材料垫抽屉

我有两个组件,AppNav 组件和 Machines 组件。AppNav 组件具有工具栏和 sidenav。我还在 AppNav 的工具栏上放置了一个过滤器按钮。在 Machines 组件中有一个 mat-drawer,需要在单击 AppNav 工具栏中的过滤器按钮后进行切换。问题是我不知道如何让两人沟通。Machines 组件不是 AppNav 组件的直接子组件,因为我通过放置在 AppNav 的 sidenav-content 中的路由器插座加载其他组件(机器等)。

从下面看组件:

DrawerService(我想通过创建它来缓解我的挫败感)

import { Injectable } from '@angular/core';
import { MatDrawer } from '@angular/material';

@Injectable({
    providedIn: 'root'
})
export class DrawerService {
    private drawer: MatDrawer;

    /**
     * setDrawer
     */
    public setDrawer(flyout: MatDrawer) {
        this.drawer = flyout;
    }

    /**
     * open
     */
    public open() {
        return this.drawer.open();
    }

    /**
     * close
     */
    public close() {
        return this.drawer.close();
    }

    /**
     * toggle …
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular6

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

Angular:检测拦截器内的重定向

我有一个会话在 20 分钟不活动后过期的应用程序。这个应用程序的用户很懒惰,所以我想他们会在早上喝完咖啡后继续使用这个应用程序,并且对与 Web API 通信会抛出的错误感到惊讶。我的想法是拦截重定向到登录页面,服务器可能会在会话到期后下次访问 Web API 时引发。

所以我写了一个拦截器:

@Injectable()
export class SessionEndInterceptor implements HttpInterceptor {

  constructor() {}

  intercept(
    req: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    {
      const initialUrl = req.url;

      return next.handle(req).pipe(
        map((event: HttpEvent<any>) => {
          const res = (event instanceof HttpResponse) && event as HttpResponse<any>;

          if (res && this.checkIfSessionEnd(initialUrl, res.url)) {
            window.location.href = this.replaceRedirectionWithCurrentLocation(
              res.url
            );
          } else {
            return event;
          }
        })
      );
    }
  }

  private checkIfSessionEnd(initialUrl: string, currentUrl: string): boolean {
    const isInitialUrlLogin = this.isLoginUrl(initialUrl); …
Run Code Online (Sandbox Code Playgroud)

angular angular6

5
推荐指数
0
解决办法
1862
查看次数

如何使用 HTML5 WebRTC 录制和保存视频

首先运行代码片段,然后阅读说明...它将为您提供结构

我想在第二个中录制、播放和保存视频video element。我面临的问题是:流正在第一个运行video-element但无法录制和保存视频

.video {
    border: 1px solid gray;
    box-shadow: 3px 4px lightgray;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<div style="text-align:center">
    <h1>Welcome to WebRTC</h1>
    <video class="video" #video autoplay controls></video>
    <video class="video" style="width:360;" autoplay controls #recordedVideo></video>
    <br>
    <button class="btn btn-warning" (click)="startRecording()">Start</button>
    <button class="btn btn-warning" (click)="stopRecording()">Stop</button>
    <button class="btn btn-warning" (click)="playRecording()">Play</button>
</div>
Run Code Online (Sandbox Code Playgroud)

------------------------ 修改并解决了问题

我在这里所做的,在Luis Estevez代码中,我在方法中声明了该事件startRecording,因为当我尝试将流块推送到 blob 数组中时,它响应了一个错误:推送方法不存在,即使我在之后创建了一个对象数组我声明了一个数组。

startRecording(stream) {
    let options = { mimeType: 'video/webm' }
    this.recordedBlobs = []
    console.log(this.recordedBlobs)
    try {
      this.mediaRecorder = new MediaRecorder(stream, …
Run Code Online (Sandbox Code Playgroud)

html javascript webrtc angular angular6

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

PrimeNg p-table 列在分组中调整大小不起作用

primeng p表可调整列大小的问题

 <p-table [resizableColumns]="true" columnResizeMode="expand" [value]="data" sortMode="multiple" [style]="{width:'100%'}" [scrollable]="true" [scrollHeight]="height" [columns]="columnList" (onColResize)="onBusinessLogicTableColResize($event)">
      <ng-template pTemplate="colgroup" let-columns>
        <colgroup>
          <col *ngFor="let col of groupHeaderColSpan" [style.width]="col.width + 'px'">
        </colgroup>
      </ng-template>
      <ng-template pTemplate="header" let-columns>
        <tr class="text-center">
          <th *ngFor="let col of columnList" [colSpan]="col.colSpan" [rowSpan]="col.rowSpan" pResizableColumn>
            {{col?.header}}
          </th>
        </tr>
        <tr class="text-center">
          <ng-template ngFor let-col [ngForOf]="columnList">
            <th *ngFor="let subheader of col?.subheaders" [colSpan]="subheader.colSpan" [rowSpan]="subheader.rowSpan">
              {{subheader?.header}}
            </th>
          </ng-template>
        </tr>
      </ng-template>
      <ng-template pTemplate="body" let-columnValue let-rowIndex="rowIndex" let-columns="columns">
        <ng-template ngFor let-col [ngForOf]="columns">
          <ng-template [ngIf]="col.hasOwnProperty('subheaders')" [ngIfElse]="showData">
            <td class="ui-resizable-column" *ngFor="let sub of col.subheaders" class="text-center">
              {{columnValue[sub.field]}} …
Run Code Online (Sandbox Code Playgroud)

html-table primeng angular angular6

5
推荐指数
0
解决办法
1833
查看次数

Angular 6 - 如何使用动态创建的 DIV 作为 ViewContainerRef

我正在 Angular 6 中使用 Renderer2 和 ViewContainerRef。\n我想将新组件动态渲染到由 Renderer2 渲染的div 。

\n\n

基本上,这就是我希望它发生的方式。

\n\n
const el = this.renderer.createElement(\'div\');\nthis.viewContainerRef: ViewContainerRef = el;\nconst factory = this.factoryResolver.resolveComponentFactory(element.elementComponentType);\nconst componentRef = this.viewContainerRef.createComponent(factory);\n
Run Code Online (Sandbox Code Playgroud)\n\n

渲染后的 HTML 应该是这样的

\n\n
<div> <--- This will be the viewContainerRef\n    <app-component></app-component> <--- this is the dynamic Component that I want to render\n</div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

\xe2\x80\x94 更新 \xe2\x80\x94

\n\n

感谢麦克斯,已经找到了我祈祷的答案。

\n\n

链接: https: //stackoverflow.com/a/44853707

\n\n

事实证明\xe2\x80\x99不需要一个新的视图viewContainerRef来显示工厂。

\n\n

模组,现在可以关闭它或参考我上面提到的链接。

\n

javascript typescript angular6

5
推荐指数
0
解决办法
5332
查看次数

部署时出现奇怪的 Angular PWA Service Worker 行为

这个问题花了我一整天的时间,我不明白发生了什么

我可以看到我的 Service Worker 已注册,但是“有时”当我在开发人员工具中单击离线时,我的域的 ServiceWorker 就会消失!

但这是主要问题,当我重新加载应用程序时,我看到以下行为。

您可以看到 ngsw.json 加载了两次,main.js 加载了 3 次!main.d3ae2084xxxx && main.bbe5073dxxxx && 然后再次 main.d3ae2084xxxx !

在此输入图像描述

如果我检查两个 ngsw.json 请求的响应,您可以看到两者都显示 main.d3ae2084xxxx 作为 main.js 的正确版本,但它仍然加载 main.bbe5073dxxxx...

第一个 ngsw.json 请求

在此输入图像描述

第二个 ngsw.json 请求

在此输入图像描述

更令人沮丧的是,实际加载的版本是以前的main.bbe5073dxxxx...!!!!

如果有人有任何想法如何发生这种情况,请告诉我。

更新...所以发现了这个优秀的小端点

https://you-app-url/ngsw/state 
Run Code Online (Sandbox Code Playgroud)

这将为您提供有关 Service Worker 的大量调试信息。

就我而言,这个

驱动程序状态:EXISTING_CLIENTS_ONLY(由于初始化失败而降级:哈希不匹配(cacheBustedFetchFromNetwork): https://dev-xxxx.net/main.eb8468bb3ed28f02d7c2.js:预期b5601102b721e0cf777691d327dc965d40d1c96e,得到83c18fdb4a594 2c964a31c119a57e0b8e16fe46e(缓存清除后)

因此,在我的情况下,这似乎是某种 CDN 问题,当我确定时将更新答案。

angular-service-worker angular6 angular-pwa

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