<html>
<head>
<title>HTML Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<div id="hover-id">
Hello World
</div>
<script>
jQuery(document).ready(function($){
$(document).on('mouseover', '#hover-id', function(){
$(this).css('color','yellowgreen');
});
$(document).on('mouseout', '#hover-id', function(){
$(this).css('color','black');
});
});
</script>
</body>
</html>
Вы должны инициализировать фрукты
export class myClass implements OnInit {
public myArray: string[] = ['banana', 'Apple, 'Kumquat']
public fruits: {test: boolean}[] = [];
constructor() {}
ngOnInit() {}
public doSomething(): void {
let my: any = {};
this.myArray.forEach( m => {
my = { test: true };
this.fruits.push(my);
});
}
}
Если вы хотите получить доступ к этому, вы должны использовать функции стрелок:
fruits: any[] = [];
doSomething() {
this.myArray.forEach(m => {
const my = { test: true };
this.fruits.push(my);
}
}
Функции стрелок приведут к его лексической ограниченности, что позволит вам получить доступ к this
из самого контекста объекта ( внешняя сфера). Подробнее об этом здесь .