Из jasmin - вызов component.instance.createNewShape()
возвращает ошибку
component.instance.createNewShape не является функцией
console.log(component.instance)
возвращает компонент, но содержит только свойства, а не его методы:
HomeComponent {selectedShape: 3, selectedMood: 1, allShapes: Array(0), shapeTypes: {…}, moodTypes: {…}, …}
selectedShape: 3
selectedMood: 1
allShapes: []
shapeTypes: {0: "Triangle", 1: "Square", 2: "Rectangle", 3: "Circle", Triangle: 0, Square: 1, Rectangle: 2, Circle: 3}
moodTypes: {0: "Normal", 1: "Happy", 2: "SuperHappy", Normal: 0, Happy: 1, SuperHappy: 2}
test: ""
shapeParams: ShapeParams {}
newShape: Circle {shapeType: 3, corners: 0, moodType: 1}
__proto__: Object
Вот код компонентов:
import { ShapeType } from './../../models/enums/shape-type.enum';
import { MoodType } from './../../models/enums/mood-type.enum';
import { Component } from '@angular/core';
import { BaseShape } from 'src/app/models/base-shape.model';
import { ShapeFactory } from 'src/app/factories/shape.factory';
import { ShapeParams } from 'src/app/models/shape-params.model';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {
public newShape: BaseShape;
public shapeParams: ShapeParams;
public selectedShape: ShapeType = ShapeType.Circle;
public selectedMood: MoodType = MoodType.Happy;
public allShapes: BaseShape[] = new Array();
public shapeTypes = ShapeType;
public moodTypes = MoodType;
constructor() {
this.reset();
}
public createNewShape(shape: ShapeType, mood: MoodType) {
this.newShape = ShapeFactory.CreateShape(shape, mood);
}
public submitShape() {
this.newShape.submitParams(this.shapeParams);
this.allShapes.push(this.newShape);
this.reset();
}
public getTotalArea() {
let sum = 0;
this.allShapes.forEach(shape => {
sum += shape.getArea();
});
return sum;
}
private reset() {
this.shapeParams = new ShapeParams();
this.newShape = ShapeFactory.CreateShape(
this.selectedShape,
this.selectedMood
);
}
}
Почему я не могу получить доступ к своим методам? (если у вас есть какие-либо вопросы или рекомендации по этому вопросу - напишите их в качестве комментария. Спасибо)