标签: angular5

Angular 2/Angular 4:如何从本地系统位置访问文件?

我的系统中的以下位置有一个JSON文件

/etc/project/system.json

我正在尝试使用我的系统路径访问此文件,但它无法正常工作.但是,如果我将此文件放在我的应用程序中的src中,它工作正常.

JSON文件路径是"/etc/project/system.json",我的应用程序路径是"/ var/www/DemoProject"

那么如何从我的本地系统访问文件.

typescript angular angular5

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

无法确定组件角度的模块5

当我使用"ng build --prod"构建Angular应用程序时,我遇到了以下错误.当我使用Angular 4构建并且使用Angular 5获得错误时,这是​​有效的.使用Angular 5"ng serve"工作正常.

错误中的错误:无法在mypath/node_modules/time-ago-pipe/time-ago-pipe.ts中确定类TimeAgoPipe的模块!将TimeAgoPipe添加到NgModule以修复它.

获取https://www.npmjs.com/package/time-ago-pipe的错误

有解决方案吗

angular angular5

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

jit_nodeValue_4(...).$ any不是Angular5函数

ERROR TypeError: jit_nodeValue_4(...).$any is not a function
at Object.eval [as handleEvent] (AddNewConnectionsComponent.html:42)
at handleEvent (core.js:13581)
at callWithDebugContext (core.js:15090)
at Object.debugHandleEvent [as handleEvent] (core.js:14677)
at dispatchEvent (core.js:9990)
at eval (core.js:10611)
at HTMLInputElement.eval (platform-browser.js:2628)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4744)
at ZoneDelegate.invokeTask (zone.js:420)
Run Code Online (Sandbox Code Playgroud)

我在表单组的必填字段上收到此错误.

我的ts文件代码

        import { Component, OnInit } from '@angular/core';
        import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms'
         import {ActivatedRoute, Router} from "@angular/router";

     @Component({
   selector: 'app-add-new-connections',
 templateUrl: './add-new-connections.component.html',
 styleUrls: ['./add-new-connections.component.scss']
})
export class AddNewConnectionsComponent {

 addNewConnectionForm: any;

 constructor(public fb: …
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular2-template angular angular4-forms angular5

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

Angular 5 Reactive Forms - 单选按钮组

我有2个单选按钮,我正在使用反应式表单,我在组件中添加了表单控件.我面临的问题是name属性必须与formControlName相同.当我将name属性设置为相同时,我只能选择1个单选按钮 - 永远不能取消选择并选择另一个.只允许我选择同一个.

this.genderControl = new FormControl("", Validators.required);
Run Code Online (Sandbox Code Playgroud)

然后添加到我的表格组

genderControl: this.genderControl,
Run Code Online (Sandbox Code Playgroud)

我的HTML:

<div class="radio-inline">
  <input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
  <label class="radio-label"> Male</label>
  <input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
  <label class="radio-label">Female</label>
</div>
Run Code Online (Sandbox Code Playgroud)

表格组

    this.personalInfo = new FormGroup({
  searchControl: this.searchControl,
  titleControl: this.titleControl,
  firstNameControl: this.firstNameControl,
  middleNameControl: this.middleNameControl,
  lastNameControl: this.lastNameControl,
  birthdayControl: this.birthdayControl,
  genderControl: this.genderControl,
  phoneControl: this.phoneControl,
  taxCanadaControl: this.taxCanadaControl,
  provinceControl: this.provinceControl,
  countryControl: this.countryControl,
  taxCountryControl: this.taxCountryControl,

  creditControl: this.creditControl
});
Run Code Online (Sandbox Code Playgroud)

angular angular-reactive-forms angular5

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

角度通用获取错误:您必须传入NgModule或NgModuleFactory才能进行自举

我按照本指南将现有的angular-cli应用程序转换为角度通用.

你可以在这里查看我的完整源代码.

我能够构建浏览器和客户端项目,但是当我在浏览器中查看应用程序时出现以下错误:

错误:您必须传入NgModule或NgModuleFactory才能在View.engine中进行自举(D:\ng-ssr-demo\dist\server.js:359545:23)

问题出在我的server.ts文件中,其中AppServerModuleNgFactory未定义,并且由于此工厂用于在快速后端引导应用程序,因此引导失败.

./server.ts:

const MockBrowser = require('mock-browser').mocks.MockBrowser;
const mock = new MockBrowser();

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();

// Express server
const app = express();

const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// Fix for window error:
const domino = require('domino');
const fs = require('fs');
const path = require('path');
const template = fs.readFileSync(path.resolve('./', 'dist', 'browser/', 'index.html')).toString();
const win = …
Run Code Online (Sandbox Code Playgroud)

javascript angular-cli angular-universal angular angular5

21
推荐指数
2
解决办法
1964
查看次数

如何在HttpClient"get"方法中传递URLSearchParams - Angular 5

我使用Angular 4.2Http服务,我使用了这样的get方法,其中params是一个URLSearchParams对象:

this.http.get(url, {headers: this.setHeaders(), search: params})
Run Code Online (Sandbox Code Playgroud)

我想迁移到Angular 5.http现在是一个像角度团队推荐的HttpClient对象.我的'搜索'键出错了.

你知道如何在我的案例中将Http迁移到HttpClient服务吗?

谢谢.

http httpclient angular angular5

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

如何在Angular 5中做一个计时器

我正在使用Angular 5.

我想知道如何在按下"播放"按钮时开始计时,以便知道自我点击后已经过了多少时间.

我还想知道是否可以停止计时器,然后能够在之前的同一时间继续.

我终于用Pardeep Jain的答案解决了我的问题.虽然这不是我想要的.我不想倒计时,我想计算持续时间.这是我最后使用的代码:

time: number = 0;
interval;

startTimer() {
  this.play = true;
  this.interval = setInterval(() => {
    this.time++;
  },1000)
}

pauseTimer() {
  this.play = false;
  clearInterval(this.interval);
}
Run Code Online (Sandbox Code Playgroud)

timer typescript angular angular5

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

错误:EBUSY:资源繁忙或锁定,rmdir

在 Windows 中执行以下步骤后发生错误:

  1. 打开一个终端: npm run start:dev
  2. 打开另一个终端: ng build --watch

但是,它可以通过使用上述命令在 Mac 中运行。package.json 配置的一部分是:

"scripts": {
"ng": "ng",
"start:dev:prod": "ng build --prod && cd dist/ && node static/server.js",
"start": "node static/server.js",
"build:prod": "ng build --prod",
"test": "ng test --code-coverage",
"lint": "ng lint",
"e2e": "ng e2e",
"start:dev": "npm run build & cd dist/ & SET APP_ENV=dev & node static/server.js",
"build": "ng build"
},
Run Code Online (Sandbox Code Playgroud)

错误日志:

Error: EBUSY: resource busy or locked, rmdir 'C:\AngularProject\dist'
Error: EBUSY: resource busy or locked, rmdir 'C:\Spring-Intern-Projects\wdpr-accounting-reference-client\dist' …
Run Code Online (Sandbox Code Playgroud)

node.js angular5

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

如何在 Angular 8 中重新加载或刷新子组件

我有两个组件,一个父级和另一个子级。

HTML 部分

<div>
  <div class="row col-md-12">
    <div class="col-md-4">
       <!-- Some HTML Code of Parent component over here -->
    </div>
    <div class="col-md-8">
      <child-component></child-component>
    </div>
 </div>
 <button class="button" (click)="reloadOnlyChild($event)">Reload Child</button>
</div>
Run Code Online (Sandbox Code Playgroud)

现在,单击此按钮后,我希望唯一的孩子重新加载或刷新。

TS部分

reloadOnlyChild(event){
  // I want to reload the child from here.
}
Run Code Online (Sandbox Code Playgroud)

我在互联网上搜索,我得到的是 Vue 或 React,但不是 Angular。

angular angular5 angular6 angular7 angular8

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

如何设置切换按钮的颜色

我有一组切换按钮.它们非常轻,在背景中消失在具有高亮度的不良显示器上.

在此输入图像描述

我该如何正确地设计它们?我宁愿将它们分配的口音主要的颜色,你可以做到这一点的常用按键的方式.

在可能的情况下,主色和强调色是暗的.所以他们的文字应该变成白色(有一些透明度).对于常规按钮,它会自动运行.

<div class="output-size">
  <mat-button-toggle-group>
    <mat-button-toggle value="letter">Letter</mat-button-toggle>
    <mat-button-toggle value="legal">Legal</mat-button-toggle>
    <mat-button-toggle value="a4">A4</mat-button-toggle>
    <mat-button-toggle value="a5">A5</mat-button-toggle>
  </mat-button-toggle-group>
</div>
Run Code Online (Sandbox Code Playgroud)

angular-material angular angular5

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