私はangleJSアプリケーションを実行しています。私はカラーピッカーを取って、div.myコードに選択された色を割り当てています。私たちは、特定のエントリのいずれかの色を選択した場合、すべてのrecords.MyコードがあるにリストのためのAngularJSウォッチ
TS(typescriptです)
let mainAngularModule = angular.module("acc-management", ['ngMaterial', 'ngRoute']);
mainAngularModule.config(routeConfig);
routeConfig.$inject = ['$routeProvider'];
function routeConfig($routeProvider, $locationProvider) {
$routeProvider
.when('/it', {
templateUrl: 'linkmanager.html'
})
.when('/UserDefinedElement', {
templateUrl: 'UserDefinedElementType.html',
controller: 'userdefinedelementtype as UDETController'
})
}
class UserTypeRecord {
public Id: number;
public Name: string;
public colorcode: any;
}
class UserDefinedElementTypeController {
private url: string;
private token: string;
public static $inject = ["$scope", '$http', '$q'];
private TestString: any;
public mycolor: string = "#f0f0f0";
public divStyle: any;
public usertypearray: UserTypeRecord[];
constructor(private $scope: ng.IScope) {
this.url = "https://apidev.smartfacts.com/sfit/";
this.watchForColor();
this.usertypearray = [
{ Id: 1, Name: "bhushan" },
{ Id: 2, Name: "suryakant" }
];
}
private watchForColor() {
this.$scope.$watch(() => this.mycolor,
(newVal, oldval) => {
console.log('this.scope', this.$scope);
this.divStyle = {
'background-color': newVal,
'color': 'white',
'width': '100px',
'height': '100px',
'font-size': 'large'
}
});
}
}
HTMLコード
ファイルを次のようにコレクション(NG-リピート)について、その色が割り当てされます<div class="demo-md-panel-content">
<table>
<thead>
<tr>
<th style="width:15%">Symbol</th>
<th style="width:15%">Name</th>
<th style="width:15%">Color</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in UDETController.usertypearray">
<td style="text-align:center">
<span ng-style="UDETController.divStyle">Testing</span>
</td>
<td>
<input type="text" ng-model="x.Name" />
</td>
<td>
<input type="color" ng-model="UDETController.mycolor" />
</td>
</td>
</tr>
</tbody>
</table>
</div>
私はその色が割り当てられたか、その特定の(行)に適用されるべき特定の行/レコードの色を選択し、それが他の(行)に割り当てるべきではないDIV
を置き換えます?現時点では私の配列ではないので、私はx.mycolorを取ることができません – Bob
私は私の答えを更新しました、それは良い一日を持っていることを願っています。 –
HTMLページでng-style = "{'background-color':x.Color}" 'x'を使用すると 'usertypearray'のobjを意味し、ngの助けを借りてそのループ内の配列の要素にアクセスできます-繰り返す。私の配列では、私は配列の要素として色を取得していない、あなたは私の配列の一部として色を取るしたいですか? – Bob