所以,我有以下代码:
<a type="button" class="btn btn-sm btn-primary btn-link" (click)="show = !show">Toggle</a>
但是当代码呈现时,HTML就是它在开发控制台中的样子
<a _ngcontent-c5="" class="btn btn-sm btn-primary btn-link" type="button">Toggle</a>
我已经尝试过将其作为按钮,这就是我得到的...
<button _ngcontent-c5="" class="btn btn-sm btn-primary btn-link" type="button">Toggle</button>
为什么会这样?
我正在使用的代码来自此Stackblitz链接:
这是我的设置:
Angular CLI: 1.7.4
Node: 8.11.1
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
@angular/cdk: 5.2.4
@angular/cli: 1.7.4
@angular/language-service: 4.4.7
@angular/material: 5.2.5
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.4.2
webpack: 3.11.0
更新
我已经编写了一个可以正常工作的函数,但是我无法定义...这是从.ts文件顶部开始的代码的迷你版本:
HTML
<button type="button" class="btn btn-sm btn-primary btn-link" (click)="showHidePaperroll(false)">Toggle</button>
.TS文件
此开始于builder(){}
下public thePaperRoll: HTMLElement;
ngAfterViewInit() {
this.thePaperRoll = document.querySelector(".box") as HTMLElement;
}
showHidePaperroll(what: boolean) {
console.log("In Show Hide paperroll");
let paperBox: any = "";
paperBox = document.getElementById(".box") as HTMLImageElement;
if (what === false) {
paperBox = this.thePaperRoll.style.opened;
console.log("PaperBox: ", paperBox);
} else {
paperBox = this.thePaperRoll.style.opened;
console.log("PaperBox: ", paperBox);
}
}
CSS
.box {
background-color: #FFCC55;
max-height: 0px;
overflow-y: hidden;
transition: ease-in-out 500ms max-height;
}
.box.opened {
max-height: 500px;
transition: ease-in-out 700ms max-height;
}