<ul class="contains-task-list">
<li><strong>I'm submitting a ...</strong></li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> bug report</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> feature request</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> support request =&gt; Please do not submit support request here, see note at the top of this template.</li>
</ul>
<p dir="auto"><strong>Current behavior</strong><br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/angular/angular/blob/bb8976608db93b9ff90a71187608a4390cbd7a07/modules/%40angular/upgrade/src/angular_js.ts#L141">angular/modules/@angular/upgrade/src/angular_js.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 141
      in
      <a data-pjax="true" class="commit-tease-sha" href="/angular/angular/commit/bb8976608db93b9ff90a71187608a4390cbd7a07">bb89766</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L141" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="141"></td>
          <td id="LC141" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-en">hasOwnProperty</span><span class="pl-kos">(</span><span class="pl-s">'angular'</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto"><code class="notranslate">window.hasOwnProperty('angular')</code> is false<br>
<code class="notranslate">!!window.angular</code> is true</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/63667/15807192/96f73cde-2b57-11e6-8793-5a96d4da4850.png"><img src="https://cloud.githubusercontent.com/assets/63667/15807192/96f73cde-2b57-11e6-8793-5a96d4da4850.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">Had to change the code manually in order to use the upgrade adapter.</p>
<p dir="auto"><strong>Expected/desired behavior</strong><br>
<code class="notranslate">window.hasOwnProperty('angular')</code> is true<br>
<code class="notranslate">!!window.angular</code> is true</p>
<ul dir="auto">
<li><strong>If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem</strong> via<br>
<a href="https://plnkr.co" rel="nofollow">https://plnkr.co</a> or similar (you can use this template as a starting point: <a href="http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5" rel="nofollow">http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5</a>).</li>
<li><strong>What is the expected behavior?</strong></li>
<li><strong>What is the motivation / use case for changing the behavior?</strong></li>
<li><strong>Please tell us about your environment:</strong></li>
<li><strong>Angular version:</strong> 2.0.0-rc.1</li>
<li><strong>Browser:</strong> tested in Chrome and Firefox latest versions</li>
<li><strong>Language:</strong> TypeScript 1.9.0-dev.20160605-1.0 with <strong>SystemJS</strong> module loader</li>
</ul>
<p dir="auto">Related: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="124233215" data-permission-text="Title is private" data-url="https://github.com/angular/angular/issues/6165" data-hovercard-type="issue" data-hovercard-url="/angular/angular/issues/6165/hovercard" href="https://github.com/angular/angular/issues/6165">#6165</a></p>
<p dir="auto">In upgrade.js (Line 284 in 2.0.0-beta.0), there is a <em>hasOwnProperty</em> check that alone, causes a TypeError if you use Object.defineProperty to define a setter function on window.angular:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var angular = {
    bootstrap: noNg,
    module: noNg,
    element: noNg,
    version: noNg
  };
  try {
    if (window.hasOwnProperty('angular')) {
      angular = window.angular;
    }
  } catch (e) {}
  exports.bootstrap = angular.bootstrap;
  exports.module = angular.module;
  exports.element = angular.element;
  exports.version = angular.version;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">angular</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">bootstrap</span>: <span class="pl-s1">noNg</span><span class="pl-kos">,</span>
    <span class="pl-c1">module</span>: <span class="pl-s1">noNg</span><span class="pl-kos">,</span>
    <span class="pl-c1">element</span>: <span class="pl-s1">noNg</span><span class="pl-kos">,</span>
    <span class="pl-c1">version</span>: <span class="pl-s1">noNg</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>
  <span class="pl-k">try</span> <span class="pl-kos">{</span>
    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-en">hasOwnProperty</span><span class="pl-kos">(</span><span class="pl-s">'angular'</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-s1">angular</span> <span class="pl-c1">=</span> <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">angular</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">e</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
  <span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">bootstrap</span> <span class="pl-c1">=</span> <span class="pl-s1">angular</span><span class="pl-kos">.</span><span class="pl-c1">bootstrap</span><span class="pl-kos">;</span>
  <span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">module</span> <span class="pl-c1">=</span> <span class="pl-s1">angular</span><span class="pl-kos">.</span><span class="pl-c1">module</span><span class="pl-kos">;</span>
  <span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">element</span> <span class="pl-c1">=</span> <span class="pl-s1">angular</span><span class="pl-kos">.</span><span class="pl-c1">element</span><span class="pl-kos">;</span>
  <span class="pl-s1">exports</span><span class="pl-kos">.</span><span class="pl-c1">version</span> <span class="pl-c1">=</span> <span class="pl-s1">angular</span><span class="pl-kos">.</span><span class="pl-c1">version</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Because of this, window.hasOwnProperty returns true even if angular is actually 'undefined' and the local angular object is now also undefined when it really should be the local copy declared just above.</p>
<p dir="auto">Here is a jsfiddle to demonstrate an example: <a href="https://jsfiddle.net/uko7uuvL/" rel="nofollow">https://jsfiddle.net/uko7uuvL/</a></p>
<p dir="auto">I propose that this actually just be a null &amp; undefined check instead:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if (window.angular) {
   angular = window.angular;
}"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">angular</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
   <span class="pl-s1">angular</span> <span class="pl-c1">=</span> <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">angular</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This would make it safe to use Object.defineProperty to add a setter function to listen for when angular is initialized.</p>