2

백그라운드에서 모든 것이 원활하게 작동하고 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.jstsconfig.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을 하드 코딩해도 아무 것도 업데이트하지 않습니다. 내가 뭘 잘못하고 있는지 전혀 모르겠지만 지금은 많이 좌절하기 시작했다. 어떤 도움을 주시겠습니까?

+0

ts 파일을 저장 한 후 새로 컴파일 하시겠습니까? 당신은 단지'app.component.js' 파일을 확인 할 수 있습니다 – yurzui

+0

(응용 프로그램 폴더에 컴파일 된) 모든 js 파일을 삭제하고 시도하십시오 – anshuVersatile

+0

'npm start'를 사용하여 실행하면 이상하게도 충분합니다! 하지만 비주얼 스튜디오에서 실행하면 typescript 컴파일러가 업데이트 된 (컴파일 된) 자바 스크립트를 생성하지 않습니다. –

답변

3

브라우저에서 F12 키를 누르면 개발자 도구가 나타납니다. 둘째

enter image description here

아래와 같이 캐시를 사용하지 않도록, 나는 캐시를 비활성화 할 수 Web.config의 단지 태그를이 섹션을 추가했다

<location path="app"> 
    <system.webServer> 
     <staticContent> 
     <clientCache cacheControlMode="DisableCache"/> 
     </staticContent> 
    </system.webServer> 
</location> 

자료 : I가 변경 See here

+1

프로덕션 모드에서 어떻게 작동해야합니까? 우리는 한 손으로 브라우저 설정을 변경하고 다른 한편으로는 캐싱을 계속 유지할 것을 사용자에게 요청할 수는 없습니다. – user1595443

0

tsconfig.json :

compileOnSave 값이 false부터 true 그리고 그것은 나를 위해 일했습니다.

관련 문제