2016-09-23 41 views
0

簡單的問題,我希望......角 - 如何強制在頁面加載進行檢查

如何使頁面加載第一無線電與下面的HTML檢查收音機嗎?

  <div class="app-margin-bottom app-margin-left"> 
       <input type="radio" 
         value="pdf" 
         ng-model="resource.type" 
         ng-click="enableUrlInput()" 
         name="resourceType" 
         required> 
        <span class="app-margin-right">PDF</span> 
       <input type="radio" 
         name="resourceType" 
         ng-model="resource.type" 
         ng-click="enableUrlInput()" 
         value="url" 
         required> URL 
      </div> 

我試過使用checked作爲attr,但這會被忽略。我也玩過將resource.type設置爲'pdf'並且使用ng檢查的指令。

+0

http://stackoverflow.com/questions/5592345/how-to-select-a-radio-button-by-default –

+0

感謝好友但檢查不起作用 –

+0

你還試過檢查=「檢查」? –

回答

1

這應該工作

<div ng-controller="MyCtrl"> 
    <div class="app-margin-bottom app-margin-left"> 
       <input type="radio" 
         value="pdf" 
         ng-checked="true" 
         ng-model="resource.type" 
         ng-click="enableUrlInput()" 
         name="resourceType" 
         required> 
        <span class="app-margin-right">PDF</span> 
       <input type="radio" 
         name="resourceType" 
         ng-model="resource.type" 
         ng-click="enableUrlInput()" 
         value="url" 
         required> URL 
      </div> 
</div> 

的jsfiddle:http://jsfiddle.net/Lvc0u55v/9955/