我正在使用MVC核心和angularjs2(使用typescript)开发应用程序。 我添加了一个新组件(View放在 Views \ Home \ Default.cshml 中),但它无法正常工作。
请参阅下面我尝试过的代码:
import { Component, OnInit } from '@angular/core';
import { IndexService } from './index.service';
@Component({
templateUrl: '/Home/Default',
//styleUrls: ['app/default/index.component.css'],
providers: [IndexService]
})
export class IndexComponent implements OnInit {
pageTitle: string = 'Sign Up';
imageWidth: number = 50;
imageMargin: number = 2;
showImage: boolean = false;
listFilter: string;
errorMessage: string;
constructor(private _indexService: IndexService) {
}
toggleImage(): void {
this.showImage = !this.showImage;
}
ngOnInit(): void {
//this._companyService.getCompanies()
// .subscribe(companies => this.companies = companies,
// error => this.errorMessage = <any>error);
}
onRatingClicked(message: string): void {
this.pageTitle = 'Sign Up: ' + message;
}
onSignUpClicked(indexService: IndexService): void {
//this._companyService.saveCompanySignUp(company).subscribe(
// (data) => {
// this.company = data;
// console.log("Item " + this.company.Id + " has been added.");
// //this.router.navigate([""]);
// },
// (error) => console.log(error)
//);
}
}
public IActionResult Default()
{
return View();
}
当我尝试运行应用程序时,我在浏览器的控制台中遇到异常。
Please specify a ShareThis Publisher Key
For help, contact support@sharethis.com
util.js:211 Google Maps API warning: SensorNotRequired https://developers.google.com/maps/documentation/javascript/error-messages#sensor-not-required
aB.j @ util.js:211
http://localhost:5000/Home/Default Failed to load resource: the server responded with a status of 500 (Internal Server Error)
zone.js:388 Unhandled Promise rejection: Failed to load /Home/Default ; Zone: <root> ; Task: Promise.then ; Value: Failed to load /Home/Default undefined
consoleError @ zone.js:388
zone.js:390 Error: Uncaught (in promise): Failed to load /Home/Default
at resolvePromise (zone.js:468)
at resolvePromise (zone.js:453)
at zone.js:502
at ZoneDelegate.invokeTask (zone.js:265)
at Zone.runTask (zone.js:154)
at drainMicroTaskQueue (zone.js:401)
at XMLHttpRequest.ZoneTask.invoke (zone.js:339)
答案 0 :(得分:0)
在组件装饰器中使用moduleId:module.id
@Component({
moduleId: module.id,
templateUrl: '/Home/Default',
//styleUrls: ['app/default/index.component.css'],
providers: [IndexService]
})