我遵循官方网站ng-switch的语法:
https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html
这就是我使用ng-switch的方式:
<div ng-switch="accessLevel">
<div class="customer" ng-switch-when="ENABLED">This is customer data</div>
<div class="customer-blurr" ng-switch-when="DISABLED"> This is disabled Customer Data</div>
<div class="customer-blurr" ng-switch-default> <demo-error [componentName]="componentname"></demo-error></div>
</div>
accessLevel是“禁用”,但我仍然得到“这是客户 数据”。
我打印出accessLevel只是为了验证它的“DIABLED”
这是我的组件:
@Component({
selector: 'customer',
templateUrl: './customer.component.html',
styleUrls: ['./customer.component.css']
})
export class CustomerComponent extends SuperChildComponent{
public allowed: boolean = false;
public accessLevel:AccessLevel =null;
public componentname:string;
constructor(private authenticationService : AuthorizationService) {
super();
this.componentname=this.constructor.name;
this.accessLevel=this.authenticationService.isUserLoggedIn()?this.authenticationService.componentAccessLevel(this.constructor.name):null;
console.log(this.constructor.name +' has '+this.accessLevel);
}
我也尝试了
ng-switch-when =“accessLevel == ENABLED”和 NG-开关时= “ACCESSLEVEL === ENABLED”
但仍然只执行第一个切换条件(这是我的想法),因为accessLevel是“已禁用”
请帮助我。
感谢。
答案 0 :(得分:2)
您的代码看起来像Angularjs 1.x语法
在Angular2中,它是*ngSwitchCase
,*ngSwitchDefault
,...
另见