Difference between Renderer and ElementRef in angular 2

前端 未结 2 1328
生来不讨喜
生来不讨喜 2020-12-08 08:32

What is the difference between Renderer and ElementRef? In Angular both are used for DOM Manipulation. I am currently using ElementRef

2条回答
  •  长情又很酷
    2020-12-08 09:01

    Do notice that you should refrain from using ElementHref as it flagged with a security risk.

    Angular 2 Documentation:

    "Permitting direct access to the DOM can make your application more vulnerable to XSS attacks. Carefully review any use of ElementRef in your code. For more detail, see the Security Guide."

    "Use this API as the last resort when direct access to DOM is needed. Use templating and data-binding provided by Angular instead. Alternatively you take a look at Renderer which provides API that can safely be used even when direct access to native elements is not supported."

提交回复
热议问题