2016-12-15 61 views
0

上下文RadioGroup中不支持Angular2 - 模板解析錯誤

我有一個Angular2應用爲其輔助功能是很重要的。我使用的輔助功能評估程序在抱怨收音機輸入具有相同的名稱,但未包含在radiogroup元素中。但是,當我把radiogroup元素,Angular2給模板解析錯誤:

Unhandled Promise rejection: Template parse errors: 
'radiogroup' is not a known element: 
1. If 'radiogroup' is an Angular component, then verify that it is part of this module. 
2. If 'radiogroup' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" 
<div> 
    [ERROR ->]<radiogroup> 
    <input type="radio" name="foo id="true" label="True" value="true" /> 
    <in"): [email protected]:6 ; Zone: <root> ; Task: Promise.then ; Value: Error:    

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-component', 
    template: ` 
    <radiogroup> 
     <input type="radio" name="my-radio" value="true" />True 
     <input type="radio" name="my-radio" value="false" />False 
    </radiogroup> 
    ` 
}) 
export class MyComponent {}; 

我已經導入FormsModule到模塊的代碼。

Plunkr

+1

請爲angular2 https://www.npmjs.com/package/ng2-radio-group找到一個收音機組模塊。 –

回答

2

radiogroup不是標準的HTML元素,它是用於像下面的屬性,(Check this PLunker

<div> 
     <input type="radio" radiogroup="alignment" name="my-radio" value="true" />True 
     <input type="radio" radiogroup="alignment" name="my-radio" value="false" />False 
    </div> 

如果要創建一個組件命名radiogroup需要聲明它在使用之前在NgModule中,

更新

您可以在沒有模板的情況下添加指令,以便Angular不會抱怨未知元素,並且它可以與基於XUL的應用程序一起使用,以構建Firefox等應用程序的用戶界面。

@Directive({ 
    selector: 'radiogroup' 
}) 
export class RadioGroupDirective { } 

這是Plunker

我還沒有在Firefox上面進行過測試,所以不知道你是否會得到所有ttributes, properties and methods of radiogroup,理想情況下它應該可以工作。

希望這有助於!

+0

謝謝!我一直在通過https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/radiogroup去建議它可以作爲一個元素使用。 –

+0

@ A.Duff:更新的答案,乾杯 –