我搜索了所有可能的答案,但没有一个有效。所有innerHTML 和PRE 标记示例都适用于代码或文本,但不适用于HTML。这正是我想要放入变量中的内容:
<div [ngStyle]="{'display':'flex', 'flex-direction':'column', 'width': '100vw', 'height': '100vh'}">
<top-header>
<a class="topHeaderItem" (click)="goToHome()">Home</a>
<a class="topHeaderItem" (click)="gotoTOC()">Contents</a>
</top-header>
Run Code Online (Sandbox Code Playgroud)
这正是我想要在屏幕上显示的内容 - 每个字符,因为它是一个教程示例。
这是我的痛苦。我的HTML:
1
<div [innerHTML]="code1">
</div>
<hr>
2
<div>
<pre>
<code [innerHTML]="code1"></code>
</pre>
</div>
<hr>
3
<div [innerHTML]=code1>
</div>
Run Code Online (Sandbox Code Playgroud)
我的组件.ts:
import {Component} from '@angular/core';
@Component({
selector: 'cs-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent {
code1 = `
<div [ngStyle]="{'display':'flex', 'flex-direction':'column', 'width': '100vw', 'height': '100vh'}">
<top-header>
<a class="topHeaderItem" (click)="goToHome()">Home</a>
<a class="topHeaderItem" (click)="gotoTOC()">Contents</a>
</top-header>
`
constructor() {
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可悲的输出:
在angular 2中,mySubject(参见代码)编译了一个complete()函数,但是在执行期间它没有错误,说没有这样的函数.我无法使用onComplete()进行编译.
import { Component, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import * as Rx from "rxjs";
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent {
myBehavior: any;
mySubject: BehaviorSubject<string>;
received = "nothing";
chatter: string[];
nxtChatter = 0;
constructor() {
this.myBehavior = new BehaviorSubject<string>("Behavior Subject Started");
this.chatter = [
"Four", "score", "and", "seven", "years", "ago"
]
}
Start() {
this.mySubject = this.myBehavior.subscribe(
(x) => { this.received = x;},
(err) …Run Code Online (Sandbox Code Playgroud) 目的:当检查或未选中特定的复选框时,程序必须根据程序化规则更改许多其他复选框。
<input type="checkbox" id="chkbox" (change)="onChangeChk($event)">Test Checkbox
onChangeChk($event) {
$event.srcElement.value = "on"; // or "off"
}
Run Code Online (Sandbox Code Playgroud)
无论 onChangeChk 如何设置复选框,该复选框都将保持其原始状态。
感谢您在这方面的帮助。:-)
通过尝试从我的应用程序中引用图像,我一直困扰着我。目录结构为:
src / app / assets / images / splashImage.png
在这种微不足道的情况下,我尝试从以下方面引用它:
src / app / app.component.html
html的第一行:
<div class="splashContainer">
Run Code Online (Sandbox Code Playgroud)
css文件:
.splashContainer {
background: url("../../assets/images/splashImage.png") no-repeat center center fixed;
Run Code Online (Sandbox Code Playgroud)
生成诊断程序说无法从-> URL路径找到文件。
我的规则显然是错误的,是从容纳html的文件夹开始计数。app为1,而src为2,这使我位于资产文件夹上方。因此,这两个../部分。
我究竟做错了什么?
提前致谢。瑜伽士
我们在应用程序中使用ngbDatePicker。由于其他用户操作,我们需要以编程方式将日历中的日期设置为不仅显示新的月份,还要特别突出显示我们要选择的DAY。
NavigateTo仅设置年和月。
我彻底检查了文档;我找到的最接近的是open()函数,该函数应该将其设置为当前ngModel值-无法使其正常工作。