0
我很難重新編譯在通過ng-bind-html-unsafe插入到DOM之後在我的$ scope.content對象中找到的Angular代碼。任何人都知道如何讓Angular消化這段代碼? 感謝提前一噸!如何在消毒的HTML字符串中消化我的Angular指令? | AngularJS
###index.html###
<body ng-controller="MainCtrl">
<h2>HTML Testing</h2>
<div ng-bind-html-unsafe="content.iPhone"></div>
</body>
###app.js###
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.content = {
iPhone: "<div ng-style=\"style.iPhoneTest\">This shows up on an iPhone</div>",
iPad: "<div ng-style=\"style.iPadTest\">This shows up on an iPad</div>",
androidPhone: "<div ng-style=\"style.androidPhoneTest\">This shows up on an Android phone</div>",
androidTablet: "<div ng-style=\"style.androidPhoneTablet\">This shows up on an Android tablet</div>"
};
$scope.style = {
iPhoneTest: {background: 'blue', color: 'black'},
iPadTest: {background: 'black', color: 'white'},
androidPhoneTest: {background: 'yellow', color: 'black'},
androidTabletTest: {background: '#111', color: 'white'}
};
});
作品:
如果你想動態決定顯示的電話,您可以在
$scope.contents
陣列由專人傳遞到指令,$compile
並追加元素這樣的。萬分感謝! – Iammesol