AngularJS - get element attributes values

后端 未结 8 1399
深忆病人
深忆病人 2020-12-04 12:24

How do you get an element attribute value?

e.g. HTML element:

         


        
8条回答
  •  无人及你
    2020-12-04 12:56

    If you are using Angular2+ following code will help

    You can use following syntax to get attribute value from html element

    //to retrieve html element

    const element = fixture.debugElement.nativeElement.querySelector('name of element'); // example a, h1, p
    

    //get attribute value from that element

      const attributeValue = element.attributeName // like textContent/href
    

提交回复
热议问题