백그라운드에서 모든 것이 원활하게 작동하고 Visual Studio에서 기본 응용 프로그램을 angular 2
으로 설정하여 심각한 문제가 발생합니다. 비주얼 스튜디오에서 빈 프로젝트를 만들고 "5 분 튜토리얼"을 매우 신중하게 따랐습니다. 마지막으로 작업을 시작한 시점이되었지만 app.component.ts
의 템플릿을 변경할 때 UI를 업데이트하는 데 문제가 발생했습니다. 브라우저에서 아무 것도 선택하지 않았습니다. 파일을 다시 시작하고 다시 실행했지만 이전 출력이 여전히 브라우저에 표시됩니다.Angularjs 2 - 템플릿 또는 구성 요소를 업데이트해도 UI가 업데이트되지 않습니다.
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
Systemjs.config.js
tsconfig.json
에서 :
다음
내 코드입니다/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// 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);
내 index.html
가 다음과 같은 내용
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading</my-app>
</body>
</html>
app.module.ts
에서, 나는
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
app.component.ts
에 있습니다
import { Component } from "@angular/core";
@Component({
selector: "my-app",
template: "<h2>Initiating {{angularVersion}}</h2>"
})
export class AppComponent {
angularVersion = "Angular2.0";
}
마지막 main.ts
에, 나는이 : 내가 시작으로 index.html
을 설정할 때
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { AppModule } from "./app.module";
platformBrowserDynamic().bootstrapModule(AppModule);
이는 "Initiating Angular2.0"
로 출력을 표시합니다 비주얼 스튜디오 2015에 파일을 저장하고 프로젝트를 실행하십시오. 내 문제는, 내가 2.1로 angularVersion 변수를 업데이 트하거나 (h2에서 p 등) 다른 것을 변경하고 파일을 다시 실행하더라도, 그것은 여전히 나를 "Initiating Angular2.0"
선물 것입니다. Template
을 하드 코딩해도 아무 것도 업데이트하지 않습니다. 내가 뭘 잘못하고 있는지 전혀 모르겠지만 지금은 많이 좌절하기 시작했다. 어떤 도움을 주시겠습니까?
ts 파일을 저장 한 후 새로 컴파일 하시겠습니까? 당신은 단지'app.component.js' 파일을 확인 할 수 있습니다 – yurzui
(응용 프로그램 폴더에 컴파일 된) 모든 js 파일을 삭제하고 시도하십시오 – anshuVersatile
'npm start'를 사용하여 실행하면 이상하게도 충분합니다! 하지만 비주얼 스튜디오에서 실행하면 typescript 컴파일러가 업데이트 된 (컴파일 된) 자바 스크립트를 생성하지 않습니다. –