2016-03-23 20 views
1

ng stili ng-yineleme ile kullanırken bir sorunum var.AngularJS ve ng stili ng-yineleme

<div style="display:table-row" ng-repeat="row in Data.Communications" id="{{row.Guid}}"> 
    <div style="display:table-cell;"> 
     <img ng-src="{{row.Path}}" ng-show="row.Path" ng-style="row.Style" /> 
     <i class="{{row.Icon}}" ng-show="row.Icon" ng-style="row.Style"></i> 
    </div> 
</div> 

Bu JSON (yüklü sunucu tarafında bir DB) aşağıdaki gibidir:: my elemanlara

$scope.Data: {"LastUpdate":"23/03/2016 11:45","Communications":[{"Guid":"2","Path":null,"Icon":"fa fa-warning","Style":"{'color':'#ffff00'}"},{"Guid":"1","Path":null,"Icon":"fa fa-warning","Style":"{'color':'#ffff00'}"},{"Guid":"3","Path":"/images/blink_yellow.gif","Icon":null,"Style":"{'width':'15px', 'height':'15px'}"}]} 

"Stil" uygulanmaz

Benim kodudur. Birisi bu sorunu çözmemde bana yardımcı olabilir mi? Temelde JSON strigified gelmiş

cevap

0

, daha önce ng-style

ng-style="doParseToJson(row.Style)" 

Kanunu Ayrıca

$scope.doParseToJson = function(style){ 
    return JSON.parse(style); 
} 

" çift qoutes yerine tek tırnak ile sarmak gerektiğine emin yanıt yapmak atamak ayrıştırmak JSON ayrıştırmak için geçerli tutmak için '{"color":"#ffff00"}' gibi.