From 29d0fc7d0b5a639f49f6425aac2c311c8379af27 Mon Sep 17 00:00:00 2001
From: liujiangnan <695541723@qq.com>
Date: Tue, 17 Sep 2019 20:38:09 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B1=95=E7=8E=B0=E9=97=AE?=
 =?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/app/form/form.component.ts | 25 +++++++++++--------------
 src/index.html                 | 10 +++++++---
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts
index 554725d..bea5651 100644
--- a/src/app/form/form.component.ts
+++ b/src/app/form/form.component.ts
@@ -1,4 +1,4 @@
-import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output} from '@angular/core';
+import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef} from '@angular/core';
 import * as _ from 'lodash'; 
 
 @Component({
@@ -24,25 +24,22 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
 
   teststr = "";
 
-  constructor() {  
+  constructor(private appRef: ApplicationRef) {  
 
   }
 
   ngOnInit() {
-    var _this = this;  
-    setTimeout(()=>{
-      this.titleObj.content = "Hello world!!!";
-      this.teststr = "************"
-    },2000);
-    // (<any>window).courseware.getData(function(data){ 
-    //   if(data){
-    //     _this.titleObj.content = data.content;
-    //   } 
-    // });
-  }
+    let _this = this;
+    (<any>window).courseware.getData(function(data){ 
+      if(data){
+        _this.titleObj = data;
+        _this.appRef.tick();
+      } 
+    });
+    
+  } 
 
   ngOnChanges() {
-
   }
 
   ngOnDestroy() {
diff --git a/src/index.html b/src/index.html
index a1d7edb..324530b 100644
--- a/src/index.html
+++ b/src/index.html
@@ -33,7 +33,7 @@
                 }
               });
             },
-            setData: function(data,callback){
+            setData: function(data,callback){ 
               let str = JSON.stringify(data);
               net.getData("setCoursewareData",{id: id,data: str},function(res){
                 if(res){
@@ -58,11 +58,15 @@
         } else {
           return {
             getData: function(callback){
-              let data = localStorage.getItem("courseware_data");
+              let data = localStorage.getItem("courseware_data");  
+              if(data){
+                data = JSON.parse(data);
+              }
               callback&&callback(data);
             },
             setData: function(data,callback){
-              localStorage.setItem("courseware_data",data);
+              console.log("******local********"); 
+              localStorage.setItem("courseware_data",JSON.stringify(data));
               callback&&callback();
             }
           }
-- 
2.21.0