有没有办法根据angular-cli@1.0.0-beta.16中的环境变量有条件地更改导入?我试图以一种不需要在客户端代码中导入服务的代码更改的方式来实现它,但是在需要时我可以指定一个构建标志来交换模拟服务.
我试过在这篇文章中使用了一种模式:
文件结构:
Run Code Online (Sandbox Code Playgroud)MyService MyServiceMock.ts MyServiceReal.ts index.ts在index.ts中,您可以拥有以下内容:
Run Code Online (Sandbox Code Playgroud)import { environment} from '../environments/environment'; export const MyService = environment.mock ? require('./MyServiceMock').MyServiceMock: require('./MyServiceReal').MyServiceReal;在您的客户端代码中,导入MyService:
Run Code Online (Sandbox Code Playgroud)import MyService from './myservice/index';
页面加载,我可以看到在单步执行代码时注入依赖项,但是编译错误(我认为是TypeScript错误)沿着这一行Cannot find name 'MyService'.
我正在为我的 angular 项目中的一个问题寻找解决方案,ng serve --watch但未检测到某些文件中的更改。
我得到了一个解决方案,上面写着使用 --poll=2000
它真的奏效了。
但是没有关于 flag poll功能的明确信息。
我们有一个 Angular 7 应用程序,我们使用 Angular CLI 进行构建,我们使用以下命令构建应用程序:
ng build --prod
我们已经检查过并将哈希值添加到文件名中。我们还使用以下内容设置了 index.html:
<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
Run Code Online (Sandbox Code Playgroud)
尽管如此,我们仍然需要在发布后要求我们的用户按 ctrl+F5 来查看最新版本,看来 Chrome 正在缓存 index.html。
无论如何,有没有更好的方法来解决这个问题。我们正在考虑在每个版本中更改 index.html 文件以将当前日期和时间附加到名称和 angular.json 中,但我们更愿意使用提供的工具来解决这个问题。
任何帮助表示赞赏。
我正在按照angular 官方网站的说明将 angular 6 更新为 angular 7 。
在更新会话期间:
我输入了更新 v7 的 angular/cli 和核心的命令
$ ng update @angular/cli@v7 @angular/core@v7。
更新后我得到了Invalid rule result: Function().
这是命令提示符输出:
added 106 packages from 85 contributors, removed 5 packages, updated 5 packages, moved 1 package and audited 36489 packages in 39.604s
found 18 vulnerabilities (12 low, 1 moderate, 5 high)
run `npm audit fix` to fix them, or `npm audit` for details
Invalid rule result: Function().
Run Code Online (Sandbox Code Playgroud)
有谁知道我为什么收到消息?
这是package.json文件中的依赖项。
"dependencies": …Run Code Online (Sandbox Code Playgroud) 我使用 angular cli 命令ng new my-app创建了新的 angular 项目
然后,我想在目录中创建名为登陆页面的模块src/app,所以我使用命令ng gm登陆页面 --routing=true创建两个文件,即一个模块和一个路由文件,如下所示:
src/app/landing-page/landing-page-routing.module.ts (254 bytes)
src/app/landing-page/landing-page.module.ts (300 bytes)
Run Code Online (Sandbox Code Playgroud)
但是现在,我想用它的根组件创建模块并在名为登陆页面的单个文件夹中路由这两个模块,那么我如何使用单个 cli 命令来做到这一点?
我收到这个奇怪的警告
Locale data for 'en-US' cannot be found. No locale data will be included for this locale
跑步时 ng build --configuration=prod --localize
这是我的 angular.json
// omitted
"i18n": {
"sourceLocale": "en-US",
"locales": {
"sr-Latn": {
"translation": "src/locale/messages.sr.xlf",
"baseHref": "/sr/"
}
}
},
// omitted
Run Code Online (Sandbox Code Playgroud)
该文档明确说明默认情况下导入 en-US。更糟糕的是,当我将 sourceLocale 更改为任何其他语言(比如“de”)时,警告消息就会消失。
手动注册 en-US 区域设置数据也无济于事
我对“platformBrowserDynamic().bootstrapModule(app.app_module)”调用有问题,错误消息是“未捕获的错误:断言错误:传入的类型不是 NgModuleType,它没有 '?mod' 属性”。但是我可以在调试过程中看到这个属性: AppModule NgModule proto emod property
app.app_module 是一个新的 @NgModule 实例,用于引导我的自定义应用程序组件。我使用了打字稿。有没有人知道为什么会发生这种情况?
另外这里还有源 JS 代码https://gist.github.com/sunnygleason/74e84acd0a03a925ec901594723ce876 我正在将它转换成 Typescript Angular CLI 项目。这是 https://github.com/AnatoliYatskevich/WIA
我更改的特定文件是: https: //github.com/AnatoliYatskevich/WIA/blob/master/src/main.ts https://github.com/AnatoliYatskevich/WIA/blob/master/src/index.html https: //github.com/AnatoliYatskevich/WIA/blob/master/src/app/app.component.ts https://github.com/AnatoliYatskevich/WIA/blob/master/src/app/app.module.ts
工具 WebStorm,来自https://www.pubnub.com/docs/angular2-javascript/pubnub-javascript-sdk 的示例格式。
谢谢
我已将我的 .NET core 3.1+Angular 9.1 更新为 Angular 10.0.2,我使用的步骤:
ng update @angular/core @angular/cli之后 VS 2019 v 16.6.3 没有显示智能感知和验证,项目运行没有问题。如果我在 VS Code 中打开项目一切正常
我发现问题就在我跑完之后 ng update @angular/cli
将项目恢复到 9.1 一切正常
谢谢
visual-studio typescript angular-cli angular visual-studio-2019
我目前在 Angular 中遇到了非常奇怪的问题。一周前我在我的一个分支上工作,它很好并且构建正确。但我不知道它是如何在下面的“ng build”期间开始抱怨的,这是我今天不断遇到的错误:
node_modules/@types/babel__traverse/index.d.ts(1136,44): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,21): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1137,37): error TS1005: ';' expected.
node_modules/@types/babel__traverse/index.d.ts(1137,43): error TS1109: Expression expected.
node_modules/@types/babel__traverse/index.d.ts(1139,1): error TS1128: Declaration or statement expected.
Run Code Online (Sandbox Code Playgroud)
我尝试了以下选项来解决此问题,但没有取得任何成功:
选项 1 - 删除和安装 node_modules, 选项 2 - 删除和安装 @types/babel_traverse
任何人都可以让我知道可能是什么原因。这是我的本地 angular/dependancy 安装版本:
Angular CLI: 7.3.10
Node: 8.15.0
OS: win32 x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, elements
... forms, http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.13.10
@angular-devkit/build-angular 0.13.9
@angular-devkit/build-ng-packagr 0.13.9 …Run Code Online (Sandbox Code Playgroud) 我在构建角度 Lib 项目时遇到错误:无法将类型实体 i10.BidiModule 解析为符号。还有另外 2 个库项目正在构建良好。这个新的 lib 项目在没有弹性布局和材料的情况下运行良好。但是当我在这个项目中使用柔性布局或材料时,我遇到了以下错误。我已经搜索了很多。有解决方案,例如包含"preserveSymlinks": true在 tsconfig.lib.json 中。不幸的是它不适合我。欢迎对此提供任何帮助。
angular-material angular-cli angular-flex-layout angular angular-library
angular-cli ×10
angular ×8
typescript ×4
javascript ×2
angular5 ×1
angular6 ×1
angular9 ×1
build ×1
ng-modules ×1
pubnub ×1
webpack ×1