我有以下代码可行。
<ngb-alert *ngIf="alertError" class="fade animate-show animate-hide" (close)="alertError = false"><strong>{{ message }}</strong></ngb-alert>
<ngb-alert *ngIf="alertSuccess" class="animate-show animate-hide" type="success" (close)="alertSuccess = false"><strong>{{ message }}</strong></ngb-alert>
但是,如果我改为以下内容,则不会
<ngb-alert *ngIf="alertError" class="fade animate-show animate-hide" type="danger" (close)="alertError = false"><strong>{{ message }}</strong></ngb-alert>
<ngb-alert *ngIf="alertSuccess" class="animate-show animate-hide" type="primary" (close)="alertSuccess = false"><strong>{{ message }}</strong></ngb-alert>
我的package.json是这样的。
"dependencies": {
"@angular/animations": "^4.3.4",
"@angular/cdk": "^2.0.0-beta.8",
"@angular/common": "^4.3.4",
"@angular/core": "^4.3.4",
"@angular/forms": "^4.3.4",
"@angular/http": "^4.3.4",
"@angular/material": "^2.0.0-beta.8",
"@angular/platform-browser": "^4.3.4",
"@angular/platform-browser-dynamic": "^4.3.4",
"@angular/router": "^4.3.4",
"@ng-bootstrap/ng-bootstrap": "~1.0.0-alpha.30",
"angular-loader": "^1.6.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"primeng": "^4.1.3",
"rxjs": "^5.4.2",
"screenshot-desktop": "^1.1.0",
"underscore": "^1.8.3",
"zone.js": "^0.8.16"
},
"devDependencies": {
"@angular/cli": "^1.2.7",
"@angular/compiler": "^4.3.4",
"@angular/compiler-cli": "^4.3.4",
"@types/jasmine": "^2.5.53",
"@types/node": "^8.0.19",
"codelyzer": "^3.1.2",
"jasmine-core": "^2.7.0",
"jasmine-spec-reporter": "^4.1.1",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.1.2",
"ts-node": "^3.3.0",
"tslint": "^5.5.0",
"typescript": "^2.4.2"
}
那么,有些专家可以告诉我这里有什么问题吗?为什么键入主要或危险不会起作用。
答案 0 :(得分:4)
我遇到了类似的问题。我的问题是Angular认为我传给它一个变量,从中读取类型。显然没有名为primary
的变量,所以它失败了。将事物改为[type]="'primary'"
完全解决了这个问题。
<ngb-alert *ngIf="alertSuccess" class="animate-show animate-hide" [type]="'primary'" (close)="alertSuccess = false"><strong>{{ message }}</strong></ngb-alert>
&#13;
答案 1 :(得分:0)
我认为你只是不允许在这里使用fade
类。
class="fade animate-show animate-hide"
如果我运行你的代码,它只会告诉我成功。
但是,如果我删除了fade
类,它会显示两条消息。
我将你的依赖列表与我的比较。
您是否尝试过更新自己的库?
您可以从命令行运行它:
npm update -D && npm update -S
你拥有的依赖关系,我没有:
"angular-loader": "^1.6.5",
"font-awesome": "^4.7.0",
"primeng": "^4.1.3",
"screenshot-desktop": "^1.1.0",
"underscore": "^1.8.3"
我特别想知道第一个angular-loader
。
你知道它的用途吗?根据它的文档,它是一个Angular JS 依赖。