title: How to fetch the <p> tag dynamic value and pass it into typescript using angular 2
body: <p>I have the below html tag in app.component.html</p>
  
  <pre><code>  &lt;p id="demo"&gt;dynamicValuegoeshere!!!&lt;/p&gt;
  </code></pre>
  
  <p>The above paragraph is having some dynamic value which is inserted by javascript. But currently i'm using type script and trying to get the above value and pass it as input argument of function.</p>
  
  <p>I'm expecting the outcome like below in app.component.ts file:</p>
  
  <pre><code>getValue(dynamicvalue){
  console.log(dynamicvalue)  //It should print the current value of the &lt;p id="demo"&gt; which is dynamicvaluegoeshere!!!!
  }
  </code></pre>
  
  <p>can someone help me to achieve this? How can I read the particular <code>&lt;P&gt;</code> tag value and pass it into app.component.ts file</p>
  
  <p><strong>Updated:</strong></p>
  
  <p>I just used the below code to fetch the result in app.component.ts file</p>
  
  <pre><code>getValue()
  {
   alert(document.getElementById("#demo").innerHTML);
  }
  </code></pre>
  
  <p><strong>app.component.html</strong>:</p>
  
  <p><code>&lt;input type="submit" value="Submit" (click)="getValue()" id="submitBtn2" class="btn-primary btn-xs"</code>></p>
  
  <p><strong>Output:</strong> </p>
  
  <pre><code>null
  </code></pre>
  
  <p>But the #demo still had value.</p>
  
  <p>Updates-latest:</p>
  
  <p><strong>app.component.ts :</strong></p>
  
  <pre><code>  @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
      })
  
       export class AppComponent implements OnInit {
        @ViewChild('demo', { static: false }) private dynamicRef: ElementRef&lt;HTMLElement&gt;;
  
       getvalue() {
         return this.dynamicRef.nativeElement.innerHTML;    
      }
  
       alert(this.getvalue);
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <p>this.dynamicRef.nativeElement.innerHTML</p>
  
  <p><a href="https://i.stack.imgur.com/UCiIy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UCiIy.png" alt="enter image description here"></a></p>
  
  <p><strong>Updates - latest:</strong></p>
  
  <p>Used <code>alert(this.getValue())</code></p>
  
  <p><strong>returned :</strong></p>
  
  <pre><code>ERROR TypeError: Cannot read property 'nativeElement' of undefined
  </code></pre>
  
  <p><strong>Final - Working Update</strong>:</p>
  
  <p>Added #demo into the <code>&lt;p&gt;</code> tag which resolved this issue. </p>
  
  <p>Thank you all...!</p>