I'm currently enrolled in an Angular course for the second time, but this time I'm using Visual Studio instead of VS Code because I need to add a C# backend.
Despite my efforts, I am still struggling with some unknown issues that I can't even search for on Google.
Right now, I am diving into topics like dependency injection and services.
I created a service with certain functionalities included.
When I tried to call something from the service in my component, it wasn't showing up in Intellisense. Even typing it manually resulted in a red underline error - quite perplexing.
I attempted to clean my solution and rebuild it, miraculously fixing the issue.
Now, I've encountered another problem where an EventEmitter in the service is not listed in Intellisense, and the component doesn't recognize the method either.
Below is a snippet of my service:
import { EventEmitter } from '@angular/core';
import { Recipe } from './recipe.model';
export class RecipeService {
recipeSelected = new EventEmitter<Recipe>();
private recipes: Recipe[] = [
new Recipe('A test recipe', 'simple test', 'https://www.maxpixel.net/static/photo/1x/Meat-Recipe-Duck-Tasty-Fry-Food-Duck-Breast-4813261.jpg'),
new Recipe('A test recipe', 'simple test', 'https://www.maxpixel.net/static/photo/1x/Meat-Recipe-Duck-Tasty-Fry-Food-Duck-Breast-4813261.jpg')
];
getRecipes() {
return this.recipes.slice();
}
}
In the service, I have Intellisense for both the getter function getRecipes() and the private array recipes, yet the recipeSelected field is not recognized.
As for my component where I use the service:
import { Component, OnInit, Input } from '@angular/core';
import { Recipe} from '../../recipe.model'
import { RecipeService } from '../recipe.service';
@Component({
selector: 'app-recipe-item',
templateUrl: './recipe-item.component.html',
styleUrls: ['./recipe-item.component.css']
})
export class RecipeItemComponent implements OnInit {
@Input() recipe: Recipe;
constructor(private recipeService: RecipeService) { }
ngOnInit() {
}
onSelected() {
}
}
I'm attempting to incorporate the EventEmitter within the onSelected method.
Has anyone experienced this peculiar behavior before, and any suggestions on how to address it?
It's worth mentioning that I have both ReSharper and Web Essentials installed.