代码之家  ›  专栏  ›  技术社区  ›  Shashank Vivek

在ID元素中获取元素-角度

  •  0
  • Shashank Vivek  · 技术社区  · 8 年前

    我有

    const saveBtnElement = fixture.debugElement.nativeElement.querySelector('#save-user');
    console.log(saveBtnElement);
    

    在那里我可以看到 console 业力测试:

    <my-button _ngcontent-c0="" id="save-user" _nghost-c3="" ng-reflect-disabled="true" ng-reflect-classnames="primary">
    <button _ngcontent-c3="" class="my-button primary" ng-reflect-ng-class="my-button primary" disabled="">
    
        <!--bindings={
      "ng-reflect-ng-if": ""
    }-->
    
        <!--bindings={
      "ng-reflect-ng-if": "false"
    }-->
        <!--bindings={
      "ng-reflect-ng-if": "true"
    }-->
        <span _ngcontent-c3="">
            Save &amp; Close
        </span>
    

    我想使用类似于

    expect(saveBtnElement.hasAttribute('disabled')).toBeTruthy();
    

    如何获得 <button> 在我的另一个部件里面 my-button ??

    1 回复  |  直到 8 年前
        1
  •  1
  •   Shashank Vivek    8 年前

    const saveBtnElement = fixture.debugElement.nativeElement.querySelector('#save-user > button');
    

    推荐文章