2016-12-06 66 views
0
<page [pagetitle]="pagePath"> 

<content> 
    <section title="Landlords" [isExpanded]="sectionExpansionStatus[0].isExpanded" (onSectionExpandChange)="onSectionExpandChange($event)"> 
     <landlord-list [categorytype]=1 *ngIf="sectionExpansionStatus[0].isExpanded"></landlord-list> 
    </section> 
    <section title="Tenants" [isExpanded]="sectionExpansionStatus[1].isExpanded" (onSectionExpandChange)="onSectionExpandChange($event)"> 
     <landlord-list [categorytype]=2 *ngIf="sectionExpansionStatus[1].isExpanded"></landlord-list> 
    </section> 
    <section title="Additional Data Field"> 
     <additional-datafields [addlDataFieldCategoryId]="30"></additional-datafields> 
    </section>  
</content> 

如何通过输入一个字符串角

我可以从我的组件这样的访问此“categorytype”。

 if (contextObj.categorytype == 1) 
     { 
      //write code here 

     } 

如果我想传递categorytype作为字符串..我该怎么做?我如何从组件访问?

回答

0

如果你只是想传递一个字段作为字符串有一对夫妇的喜欢的方式:

var strCategory = contextObj.categorytype + ""; 
var strCategory = String(contextObj.categorytype); 
var strCategory = contextObj.categorytype.toString() 

而且通过访问从组件:

使用@ViewChild访问某些元素在视图中。

使用[attr.src]创建绑定到元素的'src'属性。

使用Renderer如果由于某种原因您需要更改DOM命令。

+0

mmmm contextObj.category.toString()比声明变量两次转换为字符串容易得多。 – btinoco

+0

@ btinoco感谢提醒,然而重点是显示转换不是声明 – Yaser

0

您可以测试categorytype像这样的字符串...

if (contextObj.categorytype.toString() === "1") 
    { 
     //write code here 

    } 

或者通过它在你的组件这样

<div [categorytype]="1"></div> 

确保您声明categorytype为您的组件,如果里面的字符串使用类型。

相关问题