标签: angular-cli

什么是 npm i bootstrap@next?

当我在 angularjs 2 中配置 bootstrap 时,我在此链接中遇到了以下步骤,

如何将 bootstrap 添加到 angular-cli 项目

npm i bootstrap@next
Run Code Online (Sandbox Code Playgroud)

我明白如果我们运行以下命令,

npm i -S bootstrap@4.0.0-alpha.4 
Run Code Online (Sandbox Code Playgroud)

然后这将安装 bootstrap alpha 版本。但是如果我们给出@next,将安装哪个版本?

还有 --save 和 @next 之类的,

npm i bootstrap@next --save
Run Code Online (Sandbox Code Playgroud)

推荐哪个?以及我们如何确认已安装版本的版本?

angular-bootstrap angular-cli ng-bootstrap

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

@ngx-使用不同的模块进行翻译

我有很多模块的应用程序。我正在使用 ngx-translate 来实现多语言功能。但是,它不起作用。

i18n.module.ts

import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { TranslateModule, TranslateLoader } from "@ngx-translate/core";
import { TranslateHttpLoader } from "@ngx-translate/http-loader";
import { Http } from "@angular/http";
import { I18NComponent } from "./i18n.component";

@NgModule({
    declarations: [I18NComponent],
    imports: [
        BrowserModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: (http: Http) => new TranslateHttpLoader(http, 'i18n/', '.json'),
                deps: [Http]
            }
        })
    ],
    exports: [I18NComponent]
})

export class I18NModule { }
Run Code Online (Sandbox Code Playgroud)

i18n.组件.ts

import { Component } from '@angular/core'; …
Run Code Online (Sandbox Code Playgroud)

internationalization angular-cli ng2-translate ngx-translate angular

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

Angular 4 + Cordova +设备就绪

在Cordova上运行(或引导)基于angular-cli的应用程序的最佳方法是什么?

注意:这适用于使用多个Cordova插件的Angular 4.x应用程序.

选项A:post ng build,在你的www/index.html(www是Cordova文件夹)中你应该做以下的事情:

<script src="cordova.js"></script>
<script>
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
  console.log('onDeviceReady has been called. Lets start loading JS files.');
  var url = ['inline.bundle.js', 'polyfills.bundle.js', 'styles.bundle.js', 'vendor.bundle.js', 'main.bundle.js'];
  for(var i = 0; i < url.length; i++){
    loadJSFile(url[i]);
  }
}

function loadJSFile(url) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    head.appendChild(script);
}
</script>
Run Code Online (Sandbox Code Playgroud)

要么,

选项B:onDeviceReady()可以在main.ts(引导AppModule之前)或app.component.ts中的某个地方.

我尝试过选项A,但我的应用程序在iPad上加载时间过长.所以我想知道我是否遵循了良好的方法.提前感谢您的建议.

cordova angular-cli angular

7
推荐指数
2
解决办法
4302
查看次数

重建后重新加载页面非常慢

我最近从css转到了scss.

突然之后,我的项目在重建后加载页面的速度非常慢.(30-50秒)

我除了添加scss而不是css之外什么也没做.刚刚更改了文件并更改了.angular-cli中的设置以改为使用scss.

如果我能分享更多信息以帮助排除故障,请告诉我们.

我不知道为什么会这样.

终奌站:

webpack: Compiling...
Hash: 528351f97868ee9f6cc1                                                         
Time: 1857ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 178 kB {4} [initial]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 46.1 kB {3} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 26.6 kB {4} [initial]
chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 4.2 MB [initial]
chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry]
webpack: Compiled successfully.
webpack: Compiling...
Hash: b4d9b9ae09285a8f41b1                                                         
Time: 350ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 178 kB {4} [initial]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 44.9 …
Run Code Online (Sandbox Code Playgroud)

css sass typescript angular-cli angular

7
推荐指数
0
解决办法
421
查看次数

在angular cli项目结构中添加或放置外部Javascript文件的位置,并在typescript文件中使用它们?

在我的angular cli项目中,我需要引用不是节点包的外部js库.因此,它们不会位于node_modules文件夹下,因为它们不是由npm安装的.这些是松散的js文件.

  1. 在angular cli项目结构中,我应该在哪里添加它们作为最佳实践,以便我可以在.angular-cli.json文件中的脚本数组中添加它们?
  2. 如何在我的打字稿文件中使用它们?

下面的链接解释了我们如何在.angular-cli.json文件的脚本数组中引用它们.但是,如果它们不是节点模块,它不会告诉外部js文件应该在angular cli项目的文件夹结构中添加到何处. Angular Cli Webpack,如何添加或捆绑外部js文件?

angular-cli angular

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

我可以使用@ ngtools/webpack发出打字/声明(.d.ts)和装饰元数据(.metadata.json)文件吗?

我正在开发一个Angular库,我正在与AOT编译兼容.我已经开始使用一些gulp任务了ngc,但是我更喜欢使用,@ngtools/webpack因为它允许我使用SASS和PUG作为我的样式和模板的更直接的方法.但是,我找不到从其虚拟文件系统中获取声明或元数据文件的方法.有没有办法发出这些文件?

webpack angular-cli angular2-aot angular

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

Angular cli 安装产生 ssh 错误

使用以下命令安装 Angular cli:

npm -g install angular/cli
Run Code Online (Sandbox Code Playgroud)

使用节点 8.6 会产生此错误:

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/angular/cli.git
npm ERR! 
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

ssh node.js angular-cli

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

Angular CLI - 如何在整个应用程序中共享原型函数

我需要在字符串类上有一些全局原型函数.例如.

string.prototype.trimWhiteSpaces = function () {
  return this.replace(/ +/g, '');
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Angular CLI,我希望Angular 4应用程序中的所有字符串都可以访问此函数.我已将代码段添加到一个名为的文件中,prototypes.js并在.angular-cli.json我加载的文件中

  "scripts": [
      "assets/js/prototypes.js",
      "../node_modules/jquery/dist/jquery.min.js",
      "../node_modules/bootstrap/dist/js/bootstrap.min.js",
      "../node_modules/moment/min/moment.min.js"
    ],
Run Code Online (Sandbox Code Playgroud)

但是,当我编译项目时,我不断收到以下错误

类型'string'上不存在属性'trimWhiteSpaces'.

如何在我的应用程序中访问这些功能

javascript prototype typescript angular-cli angular

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

使用Angular Cli减少PrimeNg库的大小

PrimeNg是一个包含许多组件的大型库。我的角度应用程序仅使用其中很少的组件。我正在使用AngularCLI构建此应用程序。当我构建它时,vendor.bundle具有primeng库的全部内容。这使得捆绑包的大小很大(〜4MB)。

如何仅包含必需的组件而不包含完整的库?

angular-cli primeng angular

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

无法读取未定义的属性'NullLogger'(angular/cli 1.4.7)

今天,sudeenly我开始得到这个错误 "无法读取属性'NullLogger'未定义", 同时尝试在我的角度4应用程序中添加一个组件(ng gc abc).当我在谷歌搜索它时,人们建议我们需要将我们的cli版本更新到1.4.10.但问题是为什么我们现在为1.4.10以下的所有angular/cli版本得到这个错误? .我现在不想更新我的CLI版本.有谁知道它为什么会发生?

以下是我的package.json文件,

"dependencies": { "@angular/animations": "^4.4.6", "@angular/common": "^4.4.6", "@angular/compiler": "^4.4.6", "@angular/core": "^4.4.6", "@angular/forms": "^4.4.6", "@angular/http": "^4.4.6", "@angular/platform-browser": "^4.4.6", "@angular/platform-browser-dynamic": "^4.4.6", "@angular/router": "^4.4.6", "angular2-csv": "^0.2.5", "bootstrap": "^3.3.7", "classlist.js": "^1.1.20150312", "core-js": "^2.4.1", "font-awesome": "^4.7.0", "jquery": "^3.2.1", "lodash": "^4.17.4", "ng-select": "^1.0.0-rc.3", "ng2-dragula": "^1.5.0", "reflect-metadata": "^0.1.10", "rxjs": "^5.4.2", "toastr": "^2.1.2", "underscore": "^1.8.3", "web-animations-js": "^2.3.1", "zone.js": "^0.8.14" }, "devDependencies": { "@angular/cli": "1.4.7", "@angular/compiler-cli": "^4.4.6", "@angular/language-service": "^4.4.6", "@types/jasmine": "~2.5.53", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", "@types/toastr": "^2.1.35", "codelyzer": "~3.2.0", "jasmine-core": "~2.6.2", "jasmine-spec-reporter": …

angular-cli angular

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