标签: angular-cli

Angular2:在可观察的内部更改检测

我刚用Angular2 RC3尝试了我的第一个应用程序(使用Angular-CLI),我迷失了...

我对变量的"更改检测"有疑问word.我更新了Observable方法中的word变量subscribe,但未检测到任何更改.

app.component.ts

import { Component, Inject, OnInit } from '@angular/core';
import { VoiceRecognitionService } from './voice-recognition.service';

@Component({
  moduleId: module.id,
  selector: 'app-root',
  template: `<h1>{{word}}</h1>`, // => No prints any update
  providers: [VoiceRecognitionService],
  styleUrls: ['app.component.css']
})
export class AppComponent implements OnInit {

  private voice: VoiceRecognitionService;
  public word: string = '';

  constructor( @Inject(VoiceRecognitionService) voiceRecognition: VoiceRecognitionService) {
    this.voice = voiceRecognition;
  }

  ngOnInit() {
    this.voice.record('ca')
      .subscribe(word => {
        console.log(word); // => Is printing well the new word …
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular-cli angular2-changedetection angular

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

更改angular-cli项目中的目录结构

我一直在使用angular-cli来决定我们是否想要将它作为我们正在开始的新项目的基础.我们很长一段时间都在微软购物,并且拥有大部分服务器端知识,因此我们正在尽最大努力了解客户端框架世界的细节.我们喜欢angular-cli项目,它内置测试,捆绑,树摇动等,并保留这些功能是我的问题.我们反对需要更改默认目录结构.我们使用MVC来提供单个视图,该视图基本上是角度应用程序的index.html文件.如果我们使用标准的angular-cli项目文件夹结构执行此操作,则应用程序不会运行或构建,因为所有路径引用都在寻找.\ src\app ...

我需要知道的是我需要在angular-cli设置中进行哪些更改,以便cli的自动监视,构建,绑定,测试等功能继续与这个新结构一起使用,或者,这不是我们的事情想挖掘它将来会破裂吗?

Our folder structure:

angular-cli angular

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

Angular2生命周期钩子满载吗?

是否有生命周期钩子,告诉你是否所有内容都被加载?我有一个站点,它有几个异步工作组件.因此组件没有同时准备好.为了避免网站出现奇怪的外观,我想在其中放置一种装载横幅.但显然,我需要知道何时可以再次禁用横幅.

感谢您的任何建议或想法!

javascript angular-cli angular

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

在子目录中开发Angular App

有没有什么办法可以配置ng-serve命令在根目录下提供静态html文件,并在子目录中提供角度应用程序?


我正在开发一个角度2应用程序,并且出于搜索引擎优化的原因,我想在从根目录提供静态页面时在子目录中托管实际应用程序.像这样的东西

./
    About.html
    Home.html
    Contact.html
    /app
       app.html //Angular app goes here
Run Code Online (Sandbox Code Playgroud)

我发现ng build --base-href <base>它创建了一个可以存在于<base>子目录中的角度应用程序的生产版本,但这意味着我必须单独开发角度应用程序,然后将输出导入到我的最终项目中.我希望有一个angualr-cli解决方案,但我对任何想法持开放态度.

angularjs angular-cli angular

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

如何启动'ng serve -o'来启动index.html以外的页面?

我们的角度应用程序将在生产时嵌入到iframe中.在开发中,我们有一个文件host.html,它有一个iframe,其src是angular app的索引页面.我们可以'服务',然后手动调出host.html,它工作正常.

但是,'ng serve -o'想要打开app索引文件; 我如何让它打开host.html而不是?

angular-cli

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

在现有项目中更新Angular CLI

我正在现有项目中使用angular-cli 1.0.4,我想将版本更新为1.2.4.卸载旧版本并使用npm更新到较新版本并影响我现有项目的最佳方法是什么?它会更新package.json文件的版本.

migration upgrade angular-cli angular

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

ng服务中出现错误“无法解析模块”

我使用以下命令通过angular cli创建一个新的angular项目:

$ ng new ng5-app

当我尝试使用以下命令运行应用程序时,我一直等到所有创建的文件和所有依赖项安装完毕,以及所有这些任务完成之后

$ ng serve

出现此错误:

            ** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** Date: 2018-01-26T14:12:03.297Z
            Hash: 2238da56910f9b52c46b
            Time: 2158ms
            chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
            chunk {main} main.bundle.js (main) 2.93 kB [initial] [rendered]
            chunk {polyfills} polyfills.bundle.js (polyfills) 636 bytes [initial] [rendered]
            chunk {styles} styles.bundle.js (styles) 33.6 kB [initial] [rendered]
            chunk {vendor} vendor.bundle.js (vendor) 852 kB [initial] [rendered]

            ERROR in Error: Could not resolve module H:/ …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular

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

Angular Universal:未定义导航器

我遵循了官方的angular-cli 教程,将angular-universal集成到我现有的angular-cli应用程序中。

我可以为我的angular-cli应用程序执行SSR。但是当我尝试集成ngx-leaflet时,出现以下错误:

ReferenceError:导航器未在D:\ ng2-ssr-pwa \ dist \ server.js:40251:29定义

现在,我知道传单正在尝试访问Node上下文中不可用的导航器对象。因此,我决定延迟传单的呈现,直到此SO线程中给出的页面加载到浏览器中为止。但是我仍然遇到同样的错误。您可以在此处查看带有传单问题的演示应用程序。

./src/app/browserModuleLoader.service.ts:

import { Component, Inject, Injectable, OnInit, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';

@Injectable()
export class BrowserModuleLoaderService {
    private _L: any;

    public constructor(@Inject(PLATFORM_ID) private _platformId: Object) {
        this._init();
    }

    public getL() {
        return this._safeGet(() => this._L);
    }

    private _init() {
        if (isPlatformBrowser(this._platformId)) {
            this._requireLegacyResources();
        }
    }

    private _requireLegacyResources() {
        this._L = require('leaflet');
    }

    private _safeGet(getCallcack: () => any) …
Run Code Online (Sandbox Code Playgroud)

javascript angular-cli angular-universal angular ngx-leaflet

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

Angular保持自动重新加载

使用以下命令时,Angular会自动重新加载:

ng serve此行为仅在我的计算机上发生。

iMac 2013年末操作系统:OSX High Sierra

macos angular-cli angular macos-high-sierra

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

如何在angular cli 6+中添加组件默认值

在旧的角度cli中有一个键叫做defaults:

"defaults": {
    "schematics": {
      "collection": "@nrwl/schematics",
      "postGenerate": "npm run format",
      "newProject": [
        "app",
        "lib"
      ]
    },
    "styleExt": "scss",
    "component": {
      "changeDetection": "OnPush"
    }
  }
Run Code Online (Sandbox Code Playgroud)

这家酒店不再存在.如何在角度cli 6+中添加component/changeDetection?还有我可以添加的组件属性列表吗?

angular-cli angular angular6

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