2017-02-23 2 views
1

Ich benutze AngularJS Typoskript-Anwendung. Ich versuche Farbe von Colorpicker zu holen ab jetzt ist mir den Wert von Farbwähler bekommen, aber ich bin nicht in der Lage, die Farbe als Hintergrund für meine div.My ts-Datei zu binden, wird alsIch bin nicht in der Lage, meinen ausgewählten Wert von Colorpicker zu binden

class UserDefinedElementTypeController { 

    public mycolor: string = "#f0f0f0"; 

    constructor(private $scope: ng.IScope) { 

     this.watchForcolorChanges(); 
    } 

    private watchForcolorChanges() { 

     this.mycolor = "#0f0f0f"; 
     this.$scope.$watch(() => this.mycolor, function (newVal, oldval) { 
      console.log(oldval, newVal); 
      this.divStyle = { 
       'background-color': newVal 
      } 
     }); 
    } 
} 

mainAngularModule.controller("userdefinedelementtype", UserDefinedElementTypeController); 

HTML-Code folgt

<input type="color" ng-model="UDETController.mycolor" /> 
<div ng-style="UDETController.divStyle">Testing for background color </div> 

Fehle ich etwas?

Antwort

0

Ich habe dieses Problem gelöst. In der Funktion watchForcolorChanges habe ich meinen Code in

private watchForcolorChanges() { 

     this.$scope.$watch(() => this.mycolor, 
      (newVal, oldval) =>{ 
       console.log('this.scope', this.$scope); 
       this.divStyle = { 
        'background-color': newVal 
       } 
      }); 
    } 
geändert
Verwandte Themen