最近我选择了Angular 5,我的任务是创建一些演示应用程序.
Ng服务工作得很好,甚至ng build也没有给我任何问题.我可以不断测试我的应用程序是在开发中本地工作,还是在我的本地tomcat服务器上(使用XAMPP).
但是当我想使用生产版本时,它全都走下坡路.
ERROR in : Can't resolve all parameters for DataService in C:/Users/ak/Documents/angular5_project/src/app/services/data.service.ts: (?, [object Object]).
Run Code Online (Sandbox Code Playgroud)
我在stackoverflow上搜索了几个git存储库和其他问题.
起初,我以为我错过了一些基本的东西.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { NotFoundError } from 'app/common/not-found-error';
import { BadInput } from 'app/common/bad-input';
import { AppError } from 'app/common/app-error';
@Injectable()
export class DataService {
constructor(private url: string, private http: HttpClient ) {
}
getAll() {
return this.http.get(this.url)
.catch(this.handleError);
}
get(id) {
return …Run Code Online (Sandbox Code Playgroud) 好吧,我再次遇到了 Angular 和 javascript 问题,对于我提出的每个问题都感觉自己很愚蠢。
但让我尝试解释一下我最初的步骤以及它如何导致这个问题。因此,在我最新的项目中,我想添加一些精美的图表,让事情变得更清晰、更易于用户使用。我想到了 Chart.js...或者我应该说,ng2-charts。
事情很顺利,东西看起来不错,但是......我有两个问题。在水平条上,我想动态改变图表的大小,这样用户就不必滚动一段模糊的时间来向下滚动页面。所以,而不是这个笨重的野兽......
我尝试应用一些 Angular 魔法。后来我想在后端计算它的大小。目前,静态值就可以了。
@ViewChild('inventoryChart') itemChart : ElementRef;
constructor(public renderer: Renderer2) { }
ngAfterViewInit() {
this.renderer.setStyle(this.itemChart.nativeElement, 'height', '230px')
}
Run Code Online (Sandbox Code Playgroud)
这导致...
好的。但我的第二个问题比我想象的要困难得多。我希望图表在每个条形图上都有各自的值。我有点震惊地发现,它不是 Chart.js 的固有功能,而是一个插件。因此,我尝试通过查看图表配置来缩小问题范围。
@ViewChild('itemChart') itemChart : ElementRef;
//public context: CanvasRenderingContext2D;
public chartType: string = 'horizontalBar';
chartDatalabel: ChartLabel;
public chartDatasets: Array<any> = [
{ data: [28, 20, 6, 5, 3], label: 'Inventory per country' }
];
public chartLabels: Array<any> = ['DEU', 'SVK', 'FRA', 'GBR', 'AUT'];
public chartColors: Array<any> = [
{
backgroundColor: …Run Code Online (Sandbox Code Playgroud) 基本上就是标题所说的。我一生都无法弄清楚该警告的原因是什么。我在其他一些平台上偶然发现了类似的问题,但他们提出了一种解决方案,从去年开始似乎不再可用,如此处所示
否则,这方面的信息似乎极其稀缺。
Angular.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"jquery", "ng9-odometer"
],
"outputPath": "dist/my-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": true,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": …Run Code Online (Sandbox Code Playgroud) 我正在编写一个 Angular 应用程序,同时尽力避免根据环境变量重建我的项目。对于基本的后端 API 调用,分别使用document.location.origin和/或非常容易window.location.origin。引用托德·霍华德最臭名昭著的一句话:“它就是有效”。我必须承认,到目前为止,我的应用程序需要解决相当简单的问题,因此我缺乏一些中间概念的知识。然而,最终客户希望使用 MSAL 库将其用作备用 Active Directory,并为了方便“单点登录策略”。我忽略了在生产性构建中尝试它,意识到我不能像这样使用它......
MsalModule.forRoot({
auth: {
clientId: '<my_client_id>',
authority: '',
redirectUri: window.location.origin,
postLogoutRedirectUri: window.location.origin + "/login"
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // set to true for IE 11
},
},
Run Code Online (Sandbox Code Playgroud)
我还没有看到太多类似案例的应用解决方案。我发现这个特定问题的唯一原因是通过这个 git-issue 帖子
https://github.com/angular/angular-cli/issues/10957
我的问题是,有没有办法为 AOT 构建提供窗口对象?