标签: angular-cli

使用 http-server 提供 Angular 应用程序时找不到 404

我正在尝试使用 ng build 来使用“http-server”在生产中部署我的应用程序。

所以我运行了 ng build,然后使用 http-server 为应用程序提供服务。登录后一切正常,我可以访问每个页面。但是,当我刷新页面或单击浏览器的 URL 栏并按 Enter 键时,我收到“404 Not Found”。

使用“npm start”(ng serve)为我的应用程序提供服务时,我没有遇到此问题。

angular-cli angular

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

Angular CLI:多个通用块

相关包:Angular 5.1.1、AngularCli 1.6.1

我有一个具有公共和私人方面的应用程序。私有端在认证成功后延迟加载。我有大多数模块都使用的标准核心和共享模块。我也有共享功能模块,这些模块仅由延迟加载的应用程序的私有端使用。

共享功能模块不可避免地进入公共块,因为它们被其他模块引用。共享模块也进入该块,因为它在任何地方都被引用。因为公共块包含共享模块并且共享模块被公共端引用,所以它在应用程序第一次加载时加载。因此,包含在公共块中的私有共享功能模块也在第一页加载时加载,而不是在加载使用它们的私有延迟加载功能时加载。

题

有没有办法使用 Angular CLI 创建多个最小的公共块?至少我想要一个公共公共块和一个私有公共块。

webpack angular-cli angular

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

Docker 绑定挂载卷不传播由 angular `ng serve` 执行监视的更改事件

遵循以下步骤:

  1. 定义 Dockerfile:

    FROM node:alpine
    
    RUN yarn global add @angular/cli
    RUN yarn global add node-sass
    
    RUN mkdir /volumes
    
    WORKDIR /volumes
    
    EXPOSE 4200
    
    ENTRYPOINT ["ng"]
    
    Run Code Online (Sandbox Code Playgroud)
  2. 从这个 Dockerfile 构建一个镜像:

    docker build -t my_angular_image .
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用图像创建一个新的 angular 应用程序:

    // Create the new app
    docker run --rm --mount type=bind,src=$PWD,dst=/volumes my_angular_image new my-app --directory app --style scss
    // Change ownership of the generated app
    sudo chown -R $USER:$USER .
    
    Run Code Online (Sandbox Code Playgroud)
  4. 根据镜像,运行一个容器绑定挂载应用程序卷:

    docker run -p 4200:4200 --mount type=bind,src=$PWD/app,dst=/volumes my_angular_image serve --host 0.0.0.0
    
    Run Code Online (Sandbox Code Playgroud)

结果: 第一次编译按预期工作,容器为应用程序提供服务。但是,当更改必须ng serve在容器中监视的文件的值(来自主机)时,不会触发新的角度构建(因此,不会更新服务的应用程序)。 …

docker dockerfile mounted-volumes angular-cli angular

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

定期检查 Service Worker 更新

如何每分钟轮询服务器以检查 Service Worker 更新?

我使用了 SWUpdate angular 的可用方法,但它不轮询服务器,而是在页面刷新时获取更新和缓存,这不是必需的。

我遇到了 checkForUpdate() 方法,它非常相似,但不确定它是如何工作的?

任何帮助将不胜感激。

ngOnInit(){

   if(this.swUpdate.isEnabled){
     this.swUpdate.available.subscribe( () => {

       if(confirm("New Version available.. Load?")){
         window.location.reload();
       }


     })
   }

 }
Run Code Online (Sandbox Code Playgroud)

上面的代码在第二次重新加载时从缓存中获取数据。

service-worker progressive-web-apps angular-cli angular angular-service-worker

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

使用 intellij Ultimate 调试 angular cli 项目

如何从 Intellij utlimate 调试 angular 项目?我遵循了本教程,但没有结果。我错过了什么?我使用:
- Angular CLI:1.6.8 - 节点:6.10.0 - 操作系统:win32 x64 - Angular:5.2.4 - 打字稿:2.4.2 - webpack:3.10.0 和 Intellij 2017.3.4。

我的配置。还尝试过: 特定映射。

我使用 ng serve 运行 angular 项目(也尝试过 ng serve --sourcemaps=true)。同样在 tsconfig.json 中将 sourceMap 设置为 true。来自 chrome 调试器的文件结构:结构

javascript debugging intellij-idea angular-cli angular

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

angular 5 延迟加载 vs 动态加载

有人可以解释 angular 5 中延迟加载模块和动态组件加载之间的区别吗?我很难弄清楚何时使用什么。您能否为每个用例提供一个用例,以便我更好地理解它们?我对 angular 5 还很陌生……我知道延迟加载是关于模块的,而动态组件加载是关于组件的。

angular-cli angular-components angular5

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

将css文件导入组件

我正在使用 ngx-bootstrap,我需要将一个 css 文件导入到我的组件中,如下所示:

如果您正在使用 Angular CLI 之类的软件包捆绑器,请从 node_modules/ngx-bootstrap/datepicker/bs-datepicker.css 加载它。

(这是在组件的文档中)。

我不知道如何通过包 bundler 加载 bs-datepicker.css。

我尝试过的是:

  • 在我的组件上,我尝试加载:

styleUrls: ['node_modules/ngx-bootstrap/datepicker/bs-datepicker.css']

(没有成功,没有找到)。

该文件在此目录中:

C:\DEV\senai-5s-webapp\node_modules\ngx-bootstrap\datepicker\bs-datepicker.css

angular-cli ngx-bootstrap angular

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

如何在 maint.ts 中使用带有 angular-cli 应用程序的 platformBrowser 而不是 platformBrowserDynamic 以在 aot 模式下引导应用程序?

我正在使用带有 aot=true 和 --prod 的 angular cli 构建应用程序,因此应用程序使用 aot 进行编译并且包大小更小,但是我如何以 aot 模式引导应用程序,以便引导程序更快,如本文所述?

当前代码:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/app.module';

if (!environment.local) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
Run Code Online (Sandbox Code Playgroud)

文章提出的代码:

import { platformBrowser } from '@angular/platform-browser';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
//** where is the following file generated by angular-cli? **
import { AppModuleNgFactory } from './app/app.module.ngfactory'; …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli angular2-aot angular

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

来自 Maven 的参数化 Angular CLI 构建调用(Eirslett 的插件)

我正在构建一个打包在 WAR 静态资源中的 Java Web 应用程序。这些静态资源是通过 Angular-CLI 构建的。

Maven 构建通过 Eirslettmaven-frontend-plugin使用 npm 脚本和 npm mojo触发 ng 构建。

问题是,我想base href根据 Maven 构建参数使用自定义,但我没有设法通过环境变量或参数将它传递给 ng。

有人能告诉我如何从 Maven 将参数传递给 ng 构建吗?

代码:

pom.xml

                 <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>node install</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>npm install</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>--registry=${npm.internal.registry} --userconfig ${basedir}/.jenkins-npmrc install</arguments>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm build</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>--userconfig ${basedir}/.jenkins-npmrc run-script build</arguments>
                                <environmentVariables>
                                    <test>this-does-not-work</test>
                                </environmentVariables>
                            </configuration>
                        </execution>
                        <execution>
                            <id>npm test</id>
                            <phase>test</phase> …
Run Code Online (Sandbox Code Playgroud)

maven angular-cli maven-frontend-plugin

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

angular-cli 的 --output-hashing 总是应该与延迟加载的模块一起使用吗?

我以为我已经成功地缓存破坏了 angular-cli 的--output-hashing选项设置all为确保用户获得最新的块/更新。我意识到这并不总是适用于延迟加载的模块。

如果我只对延迟加载模块 + 构建 + 部署到 IIS进行更改,并转到属于延迟加载模块的 URL,那么我会按预期获得最新更改。

但是,如果我关闭并重新打开浏览器并转到不属于延迟加载模块的 URL,然后单击将我带到延迟加载模块的链接,则不会观察到最新更改。

几乎就像浏览器假设每当我从未更改的模块进入应用程序时没有任何更改,并且稍后在我访问已更改的模块时不会选择新块。

更奇怪的是,当我尝试复制问题以提供一些屏幕截图时,问题就消失了。

有没有其他人遇到过使用输出哈希与缓存破坏不一致的情况?

编辑:

进一步调查后,事实证明,如果我转到我网站的着陆页 [IP 地址]:[端口],那么 index.html 来自缓存。

相反,如果我转到任何其他路由 [IP 地址]:[端口]/[路由],那么 index.html 来自服务器。

由于 index.html 指向 inline.(hash).bundle.js,后者又指向延迟加载的模块,因此获取 index.html 的旧副本会导致获取旧版本的 inline.js 和其他模块。

我尝试添加<meta http-equiv="expires" content="0" />到 index.html 并清除浏览器缓存,但仍然从缓存中获取文件。

我也尝试在 web.config 中添加一个部分,但这也不起作用。

如何确保 index.html 始终来自服务器?

在此处输入图片说明

angular-cli angular

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