我想在我的 Angular 6 项目中包含一些 html 文件并使用一些外部 js 文件中的函数。如何在 Angular 6 中包含外部 html 文件和 js 文件?
我正在使用npm install socket.io-stream\n 我在我的角度组件上实现socket.io-stream如下所示:
import * as io from 'socket.io-client';\nimport * as ss from 'socket.io-stream';\nRun Code Online (Sandbox Code Playgroud)\n\n我只想创建一个像这样的双工流:
\n\nstream=ss.createStream();\nRun Code Online (Sandbox Code Playgroud)\n\n当我运行时出现此错误ng build:
ERROR in ./node_modules/socket.io-stream/lib/iostream.js\nModule not found: Error: Can't resolve 'stream' in ' \n'C:\\Users\\geoffroy\\Documents\\Mines Al\xc3\xa8s\\2A\\Stage\\WebService based \nGUI\\WebApp\\node_modules\\socket.io-stream\\lib'\nERROR in ./node_modules/socket.io-stream/lib/blob-read-stream.js\nModule not found: Error: Can't resolve 'stream' in \n'C:\\Users\\geoffroy\\Documents\\Mines Al\xc3\xa8s\\2A\\Stage\\WebService based \nGUI\\WebApp\\node_modules\\socket.io-stream\\lib'\nRun Code Online (Sandbox Code Playgroud)\n\n我不明白,因为在我的 server.js 上它似乎有效..
\n\n我尝试运行该命令npm install stream,但没有出现错误ng build。但是当我启动我的应用程序时,我的浏览器控制台中出现了一个新错误:
inherits_browser.js:5 Uncaught TypeError: Cannot read property 'prototype' of …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个包含多个模块的库,但在模块依赖性方面遇到困难。我使用 Angular 6:
"@angular-devkit/build-ng-packagr": "^0.7.0-rc.3",
"@angular-devkit/build-angular": "^0.7.0-rc.3",
"ng-packagr": "^4.0.0",
Run Code Online (Sandbox Code Playgroud)
我首先创建一个新库,使用ng g library package它创建了以下结构
projects
|- package
|- src
| |- lib
| | |- *.ts
| |-public_api.ts
|- ng-package.json
|- package.json
|- tsconfig.lib.json
Run Code Online (Sandbox Code Playgroud)
我想添加一个子包,其中包含一个依赖于主包的模块。ng-packagr 使用的子包结构(据我所知)是这样的:
projects
|- package
|- src
| |- lib
| | |- package.module.ts
| |-public_api.ts
|- ng-package.json
|- package.json
|- tsconfig.lib.json
|
|- sub-package
| |-src
| | |- sub-package.module.ts
| |- public_api.ts
| |- package.json
Run Code Online (Sandbox Code Playgroud)
子package.module依赖于package.module。我无法在 sub-package.module 中使用相对路径进行导入,因为我收到一条错误消息,指出包的所有代码都应位于 rootDir 中。
当我尝试使用添加到 tsconfig 的 …
我们知道我们可以扩展角度分量,但我还想扩展关联的模板。我的意思是,例如,我可以用其模板和骨架来定义一个抽象组件,然后子组件将被迫不仅实现抽象类方法等,而且还要实现骨架的“空间隙” html 模板。
到现在为止,我必须完全重新定义孩子中的模板。我知道我可以创建另一个组件,但通过关联建立关系。这很烦人,因为我必须创建一个要扩展的抽象类,然后创建一个组件来重新定义模板。
你是怎样做的?
是否可以对某些路线不使用角度通用?我想对我的静态页面使用角度通用。当我登录我的应用程序时,我不想使用它。我想用 /app/* 排除路由 我该怎么做?
非常感谢
这是我的 server.ts
// These are important and needed before anything else
import { enableProdMode } from '@angular/core';
// Express Engine
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import * as express from 'express';
import { join } from 'path';
import 'reflect-metadata';
import 'zone.js/dist/zone-node';
// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
// Express server
const app = express();
const …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 6 应用程序,需要将其作为 Docker 容器(Nginx 基础映像)部署到 Kubernetes 集群上。
问题:如何适应使用一次构建的相同 Docker 映像,但能够在开发和生产中运行并指向不同的 API_URL?
我的环境文件:
环境.ts
export const environment = {
production: false,
API_URL: 'https://dev-server.domain.com'
};
Run Code Online (Sandbox Code Playgroud)
环境.产品.ts
export const environment = {
production: true,
API_URL: 'https://prod-server.domain.com'
};
Run Code Online (Sandbox Code Playgroud)
我的nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml …Run Code Online (Sandbox Code Playgroud) 我需要在每秒更新的用户界面上显示时差。
我尝试的是:
组件.ts
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import { Observable, Subscription } from 'rxjs/Rx';
import { DateUtil } from '../../../framework/Utils/DateUtil';
@Component({
selector: 'app-time-difference',
templateUrl: './time-difference.component.html',
styleUrls: ['./time-difference.component.scss']
})
export class TimeDifferenceComponent implements OnInit {
orderTime = '14-09-2018 14:00:00';
today = new Date();
clock: Observable<any>;
timeDifference: string;
constructor() { }
ngOnInit() {
this.clock = Observable
.interval(1000)
.map(() => {
const orderDate = DateUtil.getDatefromString(this.orderTime, 'DD-MM-YYYY HH:mm:ss');
const timeDifference = DateUtil.getDateDiffInHours(orderDate, new Date());
return …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的登录功能:
login() {
// clear error text
this.state.errorText = "";
// try to login
this.sb.login(this.model.username, this.model.password).subscribe(x => {
// check if ok
if (x.success) {
console.log('does this print') //<-- outputs as expected
this.router.navigate(['/app']);
} else {
this.state.errorText = x.response;
}
});
}
Run Code Online (Sandbox Code Playgroud)
通过调试器,我可以看到 x.success 返回 true。我的 console.log 打印但之后, this.router.navigate(...) 行似乎没有做任何事情。没有重定向。
我尝试过使用:
this.zone.run(() => this.router.navigate(['/app']));
Run Code Online (Sandbox Code Playgroud)
但这会导致相同的结果,没有页面重定向。
我有一个端点,它根据某些参数为我提供图像。这不是一个图像网址,而是一个普通图像。因此,当我到达邮递员中的端点时,作为响应,我收到一张图像(JPG)。
我是否可以在变量中接收该图像并将其绑定到 HTML 标签中?
所有问题都有将图像 url 映射到图像的解决方案,而我的是必须在 UI 中显示的图像。
显示图像组件.ts
this.appservice.getImage().subscribe((image) => {
console.log(image);
}
)
Run Code Online (Sandbox Code Playgroud)
服务.ts
getImg() {
return this.httpClient.get('xyz.com', {headers: this.httpHeaders});
}
Run Code Online (Sandbox Code Playgroud)
我应该如何在 HTML 上显示图像变量中收到的图像?
实际日志顺序:('ngOnInit开始') ('在我之后aaya', this.policydetails) ('这里', Object.keys(this.policy).length)
预期的日志顺序:('ngOnInit开始') ('这里', Object.keys(this.policy).length) ('在我之后aaya', this.policydetails)
Component.ts 文件片段如下:
ngOnInit() {
console.log('ngOnInit started');
this.route.params.subscribe(params => {
this.getPoliciesService.getPolicyDetails(params.policyNo)
.subscribe((data: PoliciesResponse) => {
this.policy = data.data[0];
this.flattenPolicy();
console.log('Here', Object.keys(this.policy).length);
});
});
this.makePolicyTable();
}
ngAfterViewInit() {
console.log('after me aaya', this.policydetails);
const table = this.policydetails.nativeElement;
table.innerHTML = '';
console.log(table);
console.log(this.table);
table.appendChild(this.table);
console.log(table);
}
Run Code Online (Sandbox Code Playgroud)
Service.ts 文件片段如下:
getPolicyDetails(policyNo) {
const serviceURL = 'http://localhost:7001/getPolicyDetails';
console.log('getPolicyDetails service called, policyNo:', policyNo);
const params = new HttpParams()
.set('policyNo', policyNo);
console.log(params);
return this.http.get<PoliciesResponse>(serviceURL, {params} );
}
Run Code Online (Sandbox Code Playgroud)
与以下 API …
angular6 ×10
angular ×8
html ×2
node.js ×2
rxjs ×2
angular5 ×1
docker ×1
inheritance ×1
javascript ×1
kubernetes ×1
momentjs ×1
ng-packagr ×1
nginx ×1
observable ×1
router ×1
socket.io ×1
templates ×1
typescript ×1