1

What is Equivalent of -

angular.element(element).scope()

In Angular 2.0?

At Many places i have used this to get scope variable in Angular 1.x Application is there any equivalent for this in Angular 2?

If Not

How can i Remove this dependency as my code have lot of dynamic Elements, And if i map this to Angular 2, For Each Element Component Will be initialized. This Component Can have n level child and I need to access nth level child component from Parent.

Pranjal jaju
  • 416
  • 3
  • 13
  • That doesn't sound like how you do stuff in Angular2. Can you please provide more information about what you actually try to accomplish? – Günter Zöchbauer Oct 25 '16 at 05:41
  • Basically I Have Command Architecture for my application and Application gets Commands from Server for either Home, Container or View and on basis of id provided by server i was getting scope of that element and Calling an API handleCommand in their Controller. So Commands designated for Views go directly to view no one else have to intercept this command in between. – Pranjal jaju Oct 25 '16 at 05:46
  • I don't really understand what that means in detail but I'm pretty sure you should reconsider this approach for Angular2. In Angular2 you usually don't cope with the DOM directly. You update the model and let Angular2 do the DOM updates. – Günter Zöchbauer Oct 25 '16 at 05:49
  • Basically DOM Updation is not the intention here, I just have an id of element coming from server that this particular Command is designated to view with id say "view1" and that view Controller used to handle Command and updated its Model Accordingly as per Command. – Pranjal jaju Oct 25 '16 at 05:53
  • 1
    Reading from the DOM should be avoided as well. It doesn't work well with server side rendering and webworker features and is usually not what you want to do in Angular2. – Günter Zöchbauer Oct 25 '16 at 05:57
  • 1
    Got it thats what i need to know so i will modify my architecture accordingly. Thanks A Lot – Pranjal jaju Oct 25 '16 at 05:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126571/discussion-between-pranjal-jaju-and-gunter-zochbauer). – Pranjal jaju Oct 25 '16 at 06:00

1 Answers1

0

You should avoid DOM manipulation in Angular2 entirely. That said if you still need to manipulate it you can import { DOCUMENT } from '@angular/platform-browser';. Inject it in the constructor @Inject(DOCUMENT) private document and use it in a method like: this.document.getElementById();

You have another (better) option, check this out: Where does DOM manipulation belong in Angular 2?

Community
  • 1
  • 1
Xavi
  • 205
  • 6
  • 12