小编Ian*_*n A的帖子

Angular 4:Mock ElementRef

我正在试图弄清楚如何模拟ElementRef注入组件的东西.我的组件如下:

app.component.ts:

import { Component, ElementRef } from '@angular/core';

import { AppService } from './app.service';

@Component({
  selector: 'app-root',
  templateUrl: './app/app.component.html',
  styleUrls: ['./app/app.component.css']
})
export class AppComponent {
  title = 'app works!';

  constructor(private _elementRef: ElementRef, private _appService: AppService) {
    console.log(this._elementRef);
    console.log(this._appService);
  }
}
Run Code Online (Sandbox Code Playgroud)

我的测试规范如下:

app.component.spec.ts:

import { TestBed, async } from '@angular/core/testing';
import { ElementRef, Injectable } from '@angular/core';
import { AppComponent } from './app.component';
import { AppService } from './app.service';

@Injectable()
export class MockElementRef {
  nativeElement: {}  
} …
Run Code Online (Sandbox Code Playgroud)

jasmine angular

12
推荐指数
1
解决办法
6738
查看次数

具有Angular的Bootstrap 3工具提示

我正在尝试使用带有Angular JS的Boostrap 3工具提示,以便工具提示在Angular范围中显示对象的值.这在页面加载时工作正常,但是当更新范围中对象的值时,工具提示仍会显示原始值.

HTML:

<div ng-app>
<div ng-controller="TodoCtrl">
    <span data-toggle="tooltip" data-placement="bottom" title="{{name}}">Hello {{name}}</span>
    <button type="button" ng-click="changeName()">Change</button>
</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

function TodoCtrl($scope) {
    $scope.name = 'Ian';
    $scope.changeName = function () {
        $scope.name = 'Alan';
    }
}

$(document).ready(function () {
    $('span').tooltip();
});
Run Code Online (Sandbox Code Playgroud)

到目前为止,有一个例子展示了我的代码以及这个小提琴中的问题

angularjs twitter-bootstrap-3

5
推荐指数
1
解决办法
7815
查看次数

标签 统计

angular ×1

angularjs ×1

jasmine ×1

twitter-bootstrap-3 ×1