Ich versuche Razor zu verwenden, um den in einer Angular-Vorlage verwendeten HTML-Code zu generieren. Ich verwende Angular v 2.0.0. Ich habe einen Contract.cshtml, die wie folgt aussieht:Verwenden von Razor zum Generieren von Angular2-Vorlagen
<script>
System.import('contract.js').catch(function(err){ console.error(err); });
</script>
<my-contract>
<h1>Hello {{name}} this is a quick starter for angular 2 app</h1>
</my-contract>
A Contract.ts, die wie
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { ContractModule } from './app/Contract/contract.module';
platformBrowserDynamic().bootstrapModule(ContractModule);
Ein contract.component.ts sieht das wie folgt aussieht:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ContractComponent } from './contract.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ ContractComponent ],
bootstrap: [ ContractComponent ]
})
export class ContractModule { }
Und ein contract.component.ts sieht so aus:
import { Component } from '@angular/core';
@Component({
selector: 'my-contract'
})
export class ContractComponent {
public name = 'Nigel Findlater';
consturctor() {}
}
Wenn ich dies laufe ich bekommen
Error: Error: No template specified for component ContractComponent
at DirectiveNormalizer.normalizeDirective (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:13476:21) at RuntimeCompiler._createCompiledTemplate (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16869:210)
at eval (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16807:43)
at Array.forEach (native)
at eval (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16805:50)
at Array.forEach (native)
at RuntimeCompiler._compileComponents (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16804:45)
at RuntimeCompiler._compileModuleAndComponents (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16741:39)
at RuntimeCompiler.compileModuleAsync (http://localhost:2600/lib/@angular/compiler/bundles/compiler.umd.js:16732:23)
at PlatformRef_._bootstrapModuleWithZone (http://localhost:2600/lib/@angular/core/bundles/core.umd.js:6954:29)
Evaluating http://localhost:2600/contract.js
Error loading http://localhost:2600/contract.js
Ich denke, der Fehler in contract.component.ts ist, aber ich weiß nicht, wie keine Vorlage hier
In Ihrer my-contract-Komponente würden Sie eine 'template' oder' templateUrl' im Dekorateur '@ Component' angeben. https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html – silentsod
Ich möchte contract.cshtml verwenden, um die Vorlage zu generieren. Wenn ich templateUrl verwende, muss ich eine HTML-Datei verwenden und wenn ich eine Vorlage verwende, muss ich den HTML-Code direkt in den TS angeben. Sollte ich etwas anderes benutzen? –