Html内容无法使用Angular选择器进行渲染

时间:2017-06-10 12:53:41

标签: angular asp.net-mvc-5

我正在开发一个有角度的2/4应用程序,但无法在主index.cshtml页面中呈现app.component.html。但是我只能在index.cshtml页面中看到硬编码的加载一词。我的模板网址路径是否有任何问题,或者我错过了什么。我检查了开发人员工具,看不到任何错误

app.component.ts

QString str = "A text with <i>italic</i> and <b>bold</b> words."
QClipboard *clipboard = QApplication::clipboard();
QMimeData *rich_text = new QMimeData;
rich_text->setHtml(str);
clipboard->setMimeData(rich_text);

app.module.ts

import { Component} from '@angular/core'


@Component({

    selector: 'mrdb-app',
    templateUrl : './app.component.html'

})


export class AppComponent {

    pageTitle: string = "Movies Review Database";

}

app.component.html

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';


@NgModule({
    imports: [BrowserModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})

export class AppModule {

}

main.ts

<h1>Angular 2 : Getting Started</h1>>

systemjs.cofig.js

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

index.cshtml

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    System.config({        
        paths: {
            // paths serve as alias
            'npm:': '/libs/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: '/Scripts',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
            'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',
                defaultExtension: 'js',
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

2 个答案:

答案 0 :(得分:0)

尝试添加module.id以便在组件中使用相对路径,如下所示:

@Component({
moduleId: module.id,
selector: 'mrdb-app',
templateUrl: 'app.component.html',
})
export class AppComponent {}

或者更好地使用systemjs-angular-loader.js并使用相对路径而不使用modueId

答案 1 :(得分:0)

我已经解决了这个问题。问题是我试图直接调用App.Module.js而不是在layout.cshtml页面中调用main.js。 main.js负责引导app.module并启动加载。