I have been attempting to make my toolbar component send data to another component (dat.gui -> three.js). I thought creating an output emitter would be necessary, and while it is set up, it doesn't seem to be functioning properly. These components do not contain any actual HTML code.
All I want to do is emit the event with the interface containing data (currently just a boolean
, but will expand in the future). My project is available on GitHub if that would help clarify things. I have been researching different ways to work with Angular, but as a beginner, I may have made a mistake. If so, please point it out as I am unsure of what I am doing wrong.
https://github.com/GrimZero/ConfiguratorAngular
settngs.service.ts
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SettingsService {
$dataChange: Subject<any> = new Subject<any>();
}
toolbar.component.ts
import { GUI } from './../../../node_modules/three/examples/jsm/libs/dat.gui.module';
import { Settings } from '../settings';
import { SettingsService } from '../settings.service';
@Component({
selector: 'app-toolbar',
templateUrl: './toolbar.component.html',
styleUrls: ['../app.component.css']
})
export class ToolbarComponent implements OnInit {
settingsData: Settings;
constructor(private service: SettingsService) {
this.settingsData = this.defineSettings({ TimeNight: false });
}
defineSettings(config: Settings) {
const settings = { TimeNight: true };
if (config.TimeNight) {
settings.TimeNight = config.TimeNight;
}
return settings;
}
onChange() {
this.service.$dataChange.next(this.settingsData);
console.log('emitted');
}
ngOnInit() {
const gui = new GUI();
gui.add(this.settingsData, 'TimeNight').onChange(() => {
this.onChange();
});
}
}
threejs.component.ts
import { Component, OnInit } from '@angular/core';
import { Material } from '../material.js';
import { TimeOfDay } from '../time-of-day.js';
import { Threejscontroller } from '../threejscontroller.js';
import { SettingsService } from '../settings.service.js';
@Component({
selector: 'app-threejs',
templateUrl: './threejs.component.html',
styleUrls: ['../app.component.css']
})
export class ThreejsComponent implements OnInit {
threejs: Threejscontroller;
constructor(private service: SettingsService) { }
updateWebGL = (settingsData: any) => {
console.log('recieved message');
if (!settingsData.TimeNight) {
new TimeOfDay().SetTimeDay(this.threejs.scene);
} else {
new TimeOfDay().SetTimeDusk(this.threejs.scene);
}
}
ngOnInit() {
this.service.$dataChange.subscribe((value: any) => {
console.log(value);
// this.updateWebGL(value);
});
this.threejs = new Threejscontroller();
this.threejs.update();
}
}