Reputation: 15307
I create a model for assign a "language" as like this:
export interface ModelLang {
lang:string;
}
same has been added with app state as like :
import { ModelLang } from "./shared-components/state/models";
export interface AppState {
lang:ModelLang
}
But when i use in the app component assigning a string getting error as Eng not assignable to type ModelLang
- here what is the type goes wrong?
app.component.ts:
/** * Keeping nearly ideal. just keeping for router loading purpose. * *importing jquery for app!! */
import { Component, OnInit } from '@angular/core';
import { Store, select } from "@ngrx/store";
import { AppState } from "./app.state";
import { Lang } from "./shared-components/state/shared.actions";
import { ModelLang } from "./shared-components/state/models";
import * as $ from 'jquery';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
lang:ModelLang = "Eng"; //throws error
constructor(private store:Store<AppState>){}
ngOnInit(){
}
}
Upvotes: 0
Views: 25
Reputation: 26170
you're trying to assign a string to a typed variable, try the following.
lang:ModelLang = { lang: "Eng" };
Upvotes: 1