在构建我的应用程序时,我收到以下错误,这对我来说很奇怪,因为属性appName已声明:
错误在../src/app/app.service.ts(30,14):Class' AppService'错误地实现了界面' InternalStateType'。 属性' appName'在“AppService'。”
类型中缺少app.service.ts
import {Injectable} from '@angular/core';
interface InternalStateType {
[key: string]: any;
appName: string;
darkMode: boolean;
defaultLang: string;
topnavTitle: string;
messagePanelOpen: boolean;
sidenavOpen: boolean;
sidenavMode: string;
sidenavCollapse: boolean;
pageFullscreen: boolean;
pageFooter: boolean;
initial: boolean
};
/**
* App service
*/
@Injectable()
export class AppService implements InternalStateType {
// Set your states default value.
private state: InternalStateType = {
appName: 'MyApp',
darkMode: false,
defaultLang: 'en',
topnavTitle: 'MyApp',
messagePanelOpen: false,
sidenavOpen: false,
sidenavMode: 'over',
sidenavCollapse: true,
pageFullscreen: false,
pageFooter: false,
initial: false
};
public cloneState(): InternalStateType {
return JSON.parse(JSON.stringify(this.state));
}
public reloadState(state: InternalStateType) {
this.state = state;
}
public getState(prop?: any): InternalStateType {
const state = this.state;
return state.hasOwnProperty(prop) ? state[prop] : state;
}
public setState(prop: string, value: any) {
return this.state[prop] = value;
}
}
我哪里错了?感谢您的反馈
答案 0 :(得分:3)
您定义的界面只有“直接属性”,但应该实现InternalStateType
InternalStateType
state
所有属性的类是state
属性的成员。
您必须从班级中删除final class index {
public $request;
private $loader;
private $twig;
/**
* Constructor.
* definition : class preloader with default
* symfony component request class
* twig template configuration
* @param type dependency injection and function
*/
public function __construct(){
//get request info
$this->request=new request();
$this->loader = new \Twig_Loader_Filesystem(root.'/src/declarations/twigTemplate');
$this->twig = new \Twig_Environment($this->loader, array(
//'cache' => root.'/src/declarations/twigTemplate/cache',
));
}
/**
* get declaration main function.
* definition:index method is defined in a declaration
* and it is called as https://ip/company/service/app/service/doc
* @param type dependency injection and function
* @return array
*/
public function index(){
//return
return $this->twig->render("index.twig",['var'=>'foo']);
}
属性。一切都应该工作:)
答案 1 :(得分:0)
appName
类型实际上没有AppService
属性。您的state
输入为InternalStateType
且具有appName
属性。如果您确实希望AppService
实施InternalStateType
,请按以下方式对其进行定义:
@Injectable()
export class AppService implements InternalStateType {
private appName: string;
// ... define other members of `InternalStateType` here
}
如果您不打算AppService
实施InternalStateType
,请将其从类声明中删除:
export class AppService {
// ...
}