Click here to Skip to main content
15,868,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have application work in asp.net core 2.1 visual studio 2017 work with angular

but when run page it show empty page

i make inspect inside web page i get error as below

Uncaught Error: inject() must be called from an injection context
at injectInjectorOnly (core.js:1188)
at inject (core.js:1199)
at finished.component.ts:13
at Module../src/app/finished.component.ts (finished.component.ts:15)
at __webpack_require__ (bootstrap:78)
at Module../src/app/playQuiz.component.ts (main.js:592)
at __webpack_require__ (bootstrap:78)
at Module../src/app/app.module.ts (app.component.ts:8)
at __webpack_require__ (bootstrap:78)
at Module../src/main.ts (main.ts:1)

why thiserrordisplayand how to solve it
angular not have any compile error error display at run time

What I have tried:

<pre>import { Component , inject} from '@angular/core'
import { MAT_DIALOG_DATA } from '@angular/material'

@Component({


    
  template: `<h1>your score</h1>
  <h2>{{data.correct}}/{{data.total}}</h2>`

})
export class finishedComponent {
    constructor(@inject(MAT_DIALOG_DATA) private data){}
  
}
Posted
Updated 12-Feb-23 4:43am

1 solution

Try changing the private modifier data to public to make the data accessible in the template.
and Make sure to import Inject from @angular/core, and add @Inject decorator in the constructor (note the capital "I").
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900