标签: angular-cli

使用angular-cli构建其他项目可以安装的库

这是一个小背景:

我为我的组织创建了一个angular-cli(beta 17)项目,其中包含了我想与组织中的其他Angular 2项目共享的几个组件.

我开始保持简单,只需使用npm将GitHub repo安装到实现应用程序并导入组件.我认为这可以正常工作,因为它编译得很好,但是当无法找到导入组件的模板HTML文件时,在浏览器中运行应用程序会产生404错误.

我甚至尝试在组件的定义中使用内联HTML模板,但它仍然试图找到HTML文件.

是否有一种很好的方法可以使用angular-cli以允许其他项目安装和使用它的方式构建组件库应用程序?如果没有,什么是一个好的选择?谢谢你的帮助.

angular-cli angular

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

如何在自包含的Angular 2组件中包含字体

我有一个组件,需要自定义字体作为依赖项.我希望该组件能够处理字体本身的导入,因此它是可移植的.此外,我们的项目使用angular-cli,所以无论如何我无法控制webpack.config.

我希望angular-cli足够聪明,如果我在组件中进行了简单的导入,就可以移动字体,但它不会在构建时移动.

import '.my-custom-font.woff'; // doesn't work
Run Code Online (Sandbox Code Playgroud)

无论如何,简单地说我需要将字体移动到构建目录,我可以从我的css中引用它...

@font-face {
  font-family: "Custom Font";
  src: url("??????/my-custom-font.woff") format("woff")
}
Run Code Online (Sandbox Code Playgroud)

import fonts typescript angular-cli angular

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

IE11 Angular-CLI源映射不起作用

源地图显示在JavaScript包中

使用Angular-CLI 1.0和Angular 4,尽管已经//# sourceMappingURL=main.bundle.js.map捆绑了JavaScript ,但我无法获得源映射.有没有人知道如何让源图在IE-11中运行?通常这不是一个大问题,我只是切换到firefox或chrome.但我正在使用Office-js api开发一个Excel加载项,它使用嵌入式IE11浏览器来显示加载项,所以我坚持使用它.

我的tsconfig.json:

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

tsconfig.app.json:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}
Run Code Online (Sandbox Code Playgroud)

source-maps typescript internet-explorer-11 office-js angular-cli

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

Angular 2和Typescript - 从单个文件导入多个接口

我已经尝试过搜索高低的答案,但希望有人能够迅速回答这个问题.

我有一个Angular 2应用程序,我正在使用Typescript接口来帮助构建各种数据位.问题是我有一个带有多个接口的文件,当我尝试将其导入组件时,可以毫无问题地引用第一个接口,但第二个接口会导致错误.

例如 ...

myapp.model.ts
  export interface IObjectA { id: number; name: string; }
  export interface IObjectB { id: number; related: IObjectA[]; }

myapp.component.ts
  import { IObjectB } from './myapp.model';
Run Code Online (Sandbox Code Playgroud)

这导致Angular CLI编译器失败并显示错误...

... myapp.model.ts is not a module ...
Run Code Online (Sandbox Code Playgroud)

我似乎无法解决如何解决这个问题.我确定我错过了一些非常明显的东西,但你知道他们对第二双眼睛的看法.

angular-cli typescript2.0 angular

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

Angular2教程:服务中的Promise错误(类型不可分配)

我正在Angular.io网站上观看“ 英雄的角之旅 ” 教程。我已经使用Angular CLI设置了项目(请参阅本文结尾处的环境版本)。

我陷入第5点(服务):使用教程提供的相同文件,在“ hero.service.ts”的第9行中出现以下错误:

Failed to compile.

/home/myuser/angular-tour-of-heroes/src/app/hero.service.ts (9,4): Type 'Hero[]' is not assignable to type 'Promise<Hero[]>'.
  Property 'then' is missing in type 'Hero[]'.
Run Code Online (Sandbox Code Playgroud)

这是服务的代码(文件“ hero.service.ts”):

import { Injectable } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';

@Injectable()

export class HeroService {
  getHeroes(): Promise<Hero[]> {
    return Promise.resolve(HEROES);
  }
}
Run Code Online (Sandbox Code Playgroud)

这是在服务承诺解决时起作用的组件(app.component.ts)的片段:

export class AppComponent implements OnInit {
  title = 'Tour of Heroes';
  heroes: Hero[];
  selectedHero: Hero;

  constructor(private heroService: HeroService) …
Run Code Online (Sandbox Code Playgroud)

angular-promise angular-cli angular

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

为什么期望组件真实而不是定义

这是一个普遍的问题。

当使用Angular-cli架设组件时,它会自行创建第一个测试。

看起来像这样:

it('should create', () => {
 expect(component).toBeTruthy();
});
Run Code Online (Sandbox Code Playgroud)

它如何检查它是否真实且未定义?有什么区别?

提前致谢 :)

jasmine karma-jasmine angular-cli angular

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

角度2/4:每个模块加载sass变量

我们有一个定义组件的核心模块,以及一个继承该核心模块的子模块(在单个应用程序内)。子模块包含从核心组件继承的子组件。

核心模块中的每个组件都通过sass导入来导入变量。我希望子组件使用不同的不同的sass变量,但不必重新定义所有的css规则。

我该如何实现?

注意:如果每个子模块都在单独的应用程序中,那么我已经找到了解决方案。使用.angular-cli.json中的“ stylePreprocessorOptions”配置(针对每个应用程序定义),我能够使用文件名而不是文件相对路径在核心组件中导入变量。这样,每个子组件都可以使用正确的变量文件,而无需执行任何操作。但是我不想使用多个应用程序,因为我们将有40个应用程序...

谢谢

inheritance sass typescript angular-cli angular

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

Firebase身份验证不会持久存在

页面刷新后,身份验证似乎不会保留.即使使用后firebase.auth.Auth.Persistence.LOCAL.

每当我登录我的应用程序时,它都会成功将我重定向到仪表板.但是,当页面刷新时,无法访问仪表板.

这是我的代码.

文件名:login.component.ts

import { Router } from '@angular/router';
import { Component, OnInit } from '@angular/core';

import * as firebase from 'firebase/app';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore } from 'angularfire2/firestore';

@Component({
    ...
})
export class LoginComponent implements OnInit {

    email: string = '';
    password: string = '';

    constructor(public afAuth: AngularFireAuth, private router: Router, private fb: FormBuilder) {}

    signIn(credentials) {
        this.email = credentials.email;
        this.password = credentials.password;

        this.afAuth.auth.setPersistence(firebase.auth.Auth.Persistence.LOCAL).then(() => …
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-authentication angular-cli angular

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

模块构建失败:SyntaxError:“导入”和“导出”可能仅与“ sourceType:“模块””一起出现

当通过angular-cli(ng test -cc)运行具有代码覆盖率的测试时,因果报应抛出以下错误。罪魁祸首似乎是伊斯坦布尔代码覆盖率模块,因为在没有-cc的情况下运行测试不会导致任何错误。

错误(我用***替换了本地路径):

at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16),Module build failed: SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"' (1:0)
    at Parser.pp$5.raise (***\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp$1.parseStatement (***\node_modules\babylon\lib\index.js:1881:16)
    at Parser.parseStatement (***\node_modules\babylon\lib\index.js:5910:22)
    at Parser.pp$1.parseBlockBody (***\node_modules\babylon\lib\index.js:2268:21)
    at Parser.pp$1.parseTopLevel (***\node_modules\babylon\lib\index.js:1778:8)
    at Parser.parse (***\node_modules\babylon\lib\index.js:1673:17)
    at Object.parse (***\node_modules\babylon\lib\index.js:7305:37)
    at Instrumenter.instrumentSync (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:121:31)
    at Instrumenter.instrument (***\node_modules\istanbul-lib-instrument\dist\instrumenter.js:176:32)
    at Object.exports.default (***\node_modules\istanbul-instrumenter-loader\dist\index.js:25:16)
    at Compiler.compiler.plugin (***\node_modules\@angular\cli\plugins\karma-webpack-throw-error.js:10:23)
    at Compiler.applyPlugins (***\node_modules\tapable\lib\Tapable.js:61:14)
    at Watching._done (***\node_modules\webpack\lib\Compiler.js:92:17)
    at onCompiled (***\node_modules\webpack\lib\Compiler.js:51:17)
    at ***\node_modules\webpack\lib\Compiler.js:494:13
    at next (***\node_modules\tapable\lib\Tapable.js:202:11)
    at Compiler.<anonymous> (***\node_modules\webpack\lib\CachePlugin.js:62:5)
    at Compiler.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:206:13)
    at ***\node_modules\webpack\lib\Compiler.js:491:10
    at Compilation.applyPluginsAsyncSeries (***\node_modules\tapable\lib\Tapable.js:195:46) …
Run Code Online (Sandbox Code Playgroud)

istanbul webpack angular-cli karma-webpack angular

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

您如何使用NPM链接库和Angular CLI应用程序监视更改?

我有以下设置:

  1. 我正在开发的本地UI库
  2. 正在使用该库的Angular应用程序
  3. 我正在使用NPM链接,这样就不必在每次要测试使用它的应用程序中的更改时都发布该库。
  4. Angular应用程序通过Angular CLI(ng serve --aot)提供服务
  5. 我正在监视UI库的更改,以便它使用 gulp watch

我有两个问题:

每当我对库进行更改时,gulp watch都会触发新的构建。但是,此构建失败,并出现以下错误:

Error: EPERM: operation not permitted, unlink

我可以通过触发UI库的手动构建来解决此问题,但是还有另一个问题:正在运行的应用程序会看到对链接库的更改,并在UI库构建开始后立即触发自己的构建。这将创建竞争条件,从而Angular CLI将不会等待UI库完成构建。

使用Angular CLI应用程序使用NPM链接来监视本地NPM库中的更改的正确的标准方法是什么?

javascript node.js npm angular-cli angular

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