从控制器Angular4调用jQuery函数

从控制器Angular4调用jQuery函数,jquery,angular,Jquery,Angular,当异步函数完成时,我尝试从Angular 4控制器调用jquery函数,但我找不到如何调用 我的控制器: import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { MyService } from '../my.service'; declare var $: any; @Component({ selector: 'slider', encapsulation: ViewEncaps

当异步函数完成时,我尝试从Angular 4控制器调用jquery函数,但我找不到如何调用

我的控制器:

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { MyService } from '../my.service';

declare var $: any;

@Component({
  selector: 'slider',
  encapsulation: ViewEncapsulation.None,
  templateUrl: './slider.component.html',
  styleUrls: ['./slider.component.css']
})
export class SliderComponent implements OnInit {

  banners: Promise<String[]>;

  ngOnInit(): void {
    this.banners.then(function(result) { 
            // HERE MUST BE MY CODE FUNCTION
    });
  }

  constructor(private myService: MyService) {
        this.banners = this.myService.getBanners();

    }
}
从'@angular/core'导入{Component,OnInit,viewenclosuration};
从“../my.service”导入{MyService};
声明var$:任何;
@组成部分({
选择器:“滑块”,
封装:视图封装。无,
templateUrl:'./slider.component.html',
样式URL:['./slider.component.css']
})
导出类SliderComponent实现OnInit{
横幅:承诺;
ngOnInit():void{
this.banners.then(函数(结果){
//这里必须是我的代码函数
});
}
构造函数(私有myService:myService){
this.banners=this.myService.getBanners();
}
}
和我的模板:

<div id="slider1_container" style="position: relative; margin: 0 auto; width:600px; height:300px; left:0px; top:0px;">

        <!-- Slides Container -->
        <div u="slides" style="cursor: move; position: absolute; left: 0px; top: 0px; width: 600px; height: 300px;
            overflow: hidden;">
            <div *ngFor="let b of banners | async">
                <img u="image" src="{{ b }}" />
            </div>
        </div>

        <!-- Trigger -->
        <div class="slideshow-block">

            <div style="margin: 0 4px; display: none; ">
                <input id="stTransitionName" readonly type="text" style="width:200px;height:22px;" />
            </div>
            <div style="display: none; margin: 0 4px;">
                <input id="stTransition" readonly type="text" style="width:100%;height:22px;" />
            </div>

            </div>
    </div>

当我所有的横幅都被加载时,我需要调用jquery函数来实现移动效果。以前,我只使用HTML和jquery调用了
window.ready
函数上的函数,但现在这没有用了,因为它是一个异步函数

谢谢。

///
从'angular2/core'导入{Component,AfterViewInit};
@组成部分({
选择器:“您的应用程序”,
templateUrl:“./app.component.html”
})
导出类AppComponent实现AfterViewInit{
ngAfterViewInit(){
//jQuery代码在这里
$(“#yourElement”).text(“你好!”;
}

}
您不能使用
窗口。ready
在angular中不可用。AfterViewInit函数可以,但我需要按函数名调用函数,例如:我声明了
函数hello(){alert('hello!');}
但在控制器中,我需要按函数名调用它,
hello()