<a href='https://github.com/angular/angular.js/edit/v1.2.x/src/ng/directive/booleanAttrs.js?message=docs(ngSelected)%3A%20describe%20your%20change...#L268' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>



<a href='https://github.com/angular/angular.js/tree/v1.2.28/src/ng/directive/booleanAttrs.js#L268' class='view-source pull-right btn btn-primary'>
  <i class="glyphicon glyphicon-zoom-in">&nbsp;</i>View Source
</a>


<header class="api-profile-header">
  <h1 class="api-profile-header-heading">ngSelected</h1>
  <ol class="api-profile-header-structure naked-list step-list">
    
    <li>
      - directive in module <a href="api/ng">ng</a>
    </li>
  </ol>
</header>



<div class="api-profile-description">
  <p>The HTML specification does not require browsers to preserve the values of boolean attributes
such as selected. (Their presence means true and their absence means false.)
If we put an Angular interpolation expression into such an attribute then the
binding information would be lost when the browser removes the attribute.
The <code>ngSelected</code> directive solves this problem for the <code>selected</code> attribute.
This complementary directive is not removed by the browser and so provides
a permanent reliable place to store the binding information.</p>

</div>




<div>
  

  
  <h2>Directive Info</h2>
  <ul>
    
    <li>This directive executes at priority level 100.</li>
  </ul>

  
  <h2 id="usage">Usage</h2>
  <div class="usage">
  
    <ul>
    <li>as attribute:
        <pre><code>&lt;OPTION&#10;  ng-selected=&quot;&quot;&gt;&#10;...&#10;&lt;/OPTION&gt;</code></pre>
      </li>
    
  </div>
  
<section class="api-section">
  <h3>Arguments</h3>

<table class="variables-matrix input-arguments">
  <thead>
    <tr>
      <th>Param</th>
      <th>Type</th>
      <th>Details</th>
    </tr>
  </thead>
  <tbody>
    
    <tr>
      <td>
        ngSelected
        
        
      </td>
      <td>
        <a href="" class="label type-hint type-hint-expression">expression</a>
      </td>
      <td>
        <p>If the <a href="guide/expression">expression</a> is truthy,
    then special attribute &quot;selected&quot; will be set on the element</p>

        
      </td>
    </tr>
    
  </tbody>
</table>

</section>
  


  
  <h2 id="example">Example</h2><p>

<div>
  <a ng-click="openPlunkr('examples/example-example47')" class="btn pull-right">
    <i class="glyphicon glyphicon-edit">&nbsp;</i>
    Edit in Plunker</a>

  <div class="runnable-example"
      path="examples/example-example47">

  
    <div class="runnable-example-file" 
      name="index.html"
      language="html"
      type="html">
      <pre><code>Check me to select: &lt;input type=&quot;checkbox&quot; ng-model=&quot;selected&quot;&gt;&lt;br/&gt;&#10;&lt;select&gt;&#10;  &lt;option&gt;Hello!&lt;/option&gt;&#10;  &lt;option id=&quot;greet&quot; ng-selected=&quot;selected&quot;&gt;Greetings!&lt;/option&gt;&#10;&lt;/select&gt;</code></pre>
    </div>
  
    <div class="runnable-example-file" 
      name="protractor.js"
      type="protractor"
      language="js">
      <pre><code>it(&#39;should select Greetings!&#39;, function() {&#10;  expect(element(by.id(&#39;greet&#39;)).getAttribute(&#39;selected&#39;)).toBeFalsy();&#10;  element(by.model(&#39;selected&#39;)).click();&#10;  expect(element(by.id(&#39;greet&#39;)).getAttribute(&#39;selected&#39;)).toBeTruthy();&#10;});</code></pre>
    </div>
  

    <iframe class="runnable-example-frame" src="examples/example-example47/index.html" name="example-example47"></iframe>
  </div>
</div>


</p>

</div>


