Angularjs 在Angular 1.5中,如何将属性组件绑定为布尔值?

Angularjs 在Angular 1.5中,如何将属性组件绑定为布尔值?,angularjs,angularjs-directive,binding,components,angularjs-components,Angularjs,Angularjs Directive,Binding,Components,Angularjs Components,我想知道在Angular 1.5中,当您使用组件时,是否有一种简单的方法可以绑定布尔属性,而不必转换为带@的字符串 例如,我有两个组件“app menu”和“app menuitem”,没有transclude。“应用程序菜单”只有一个属性,其中包含要创建“应用程序菜单项”的项目列表 在menuitem组件中: angular.module('app') .component('appMenuitem', { transclude: false, controll

我想知道在Angular 1.5中,当您使用组件时,是否有一种简单的方法可以绑定布尔属性,而不必转换为带@的字符串

例如,我有两个组件“app menu”和“app menuitem”,没有transclude。“应用程序菜单”只有一个属性,其中包含要创建“应用程序菜单项”的项目列表

在menuitem组件中:

angular.module('app')
    .component('appMenuitem', {
      transclude: false,
      controller: menuitemController,
      bindings: {
        label: '@',  
        isactive: '@' //<--- The problem is here because the boolean is converted as string
      },
      templateUrl: 'angular/components/simple/menuitem/menuitem.html'
    });
angular.module('app')
.component('appMenuitem'{
排除:错误,
控制器:menuitemController,
绑定:{
标签:“@”,

isactive:'@'/只需使用单向绑定而不是字符串绑定:

angular.module('app')
    .component('appMenuitem', {
      transclude: false,
      controller: menuitemController,
      bindings: {
        label: '@',  
        isactive: '<'
      },
      templateUrl: 'angular/components/simple/menuitem/menuitem.html'
    });
angular.module('app')
.component('appMenuitem'{
排除:错误,
控制器:menuitemController,
绑定:{
标签:“@”,

isactive:“在角度1.5以上的范围内,您可以使用

angular.module('app')
    .component('appMenuitem', {
      transclude: false,
      controller: menuitemController,
      bindings: {
        label: '@',  
        isactive: '@' //<--- The problem is here because the boolean is converted as string
      },
      templateUrl: 'angular/components/simple/menuitem/menuitem.html'
    });
angular.module('app')
    .component('appMenuitem', {
      transclude: false,
      controller: menuitemController,
      bindings: {
        label: '@',  
        isactive: '<'
      },
      templateUrl: 'angular/components/simple/menuitem/menuitem.html'
    });
isactive: '<'
<input type="text" disabled>
<input type="text" disabled="disabled">
bindings: {
  paramSomething: '@something'
}
function $onChanges(changes) {
  if (changes.paramSomething) {
    switch (typeof this.paramSomething) {
      case 'string': {
        this.isSomething = parseBoolean(this.paramSomething, true);
        break;
      }
      case 'undefined': {
        this.isSomething = false;
        break;
      }
    }
  }
<my-component something></my-component>