我創建一個Windows應用商店應用程序(或Metro應用,或不管他們稱之爲)使用AngularJS。「無法添加動態內容」使用AngularJS爲Windows Store應用,但它的工作原理
我解決了Javascript運行時錯誤「無法添加動態內容」導致應用程序崩潰(請參閱here),並且一切正常,直到我開始使用指令(undestand angular.module.directive)。
現在,我有一個「無法添加動態內容」,但在控制檯日誌。請注意,該應用程序不會崩潰,事實上,該應用程序按預期工作!
如果我只是忽略錯誤(我不喜歡),我可以做任何事情?
一個「時鐘」的應用程序的一個代碼來說明: 該應用程序沒有顯示正確的時,格式化,並遞增每秒。 DOM是我期望的。
感謝,
的index.html:
<!doctype html>
<html lang="en" ng-app="phonecat">
<head>
<meta charset="utf-8">
<title>Google Phone Gallery</title>
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="lib/jquery-1.8.2-win8-1.0.min.js"></script>
<script type="text/javascript">
jQuery.isUnsafe = true;
</script>
<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>
<script src="lib/angular/angular-resource.js"></script>
</head>
app.js
angular.module('phonecat', ['phonecatFilters', 'phonecatServices']).config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/phones', {templateUrl: 'partials/phone-list.html',controller: PhoneListCtrl}).
otherwise({redirectTo: '/phones'});
}])
.directive('myCurrentTime', function($timeout, dateFilter) {
return {
restrict: 'E',
replace: true,
template: '<div> Current time is: <span>{{time}}</span></div>',
link: function (scope, element, attrs) {
var timeoutId;
function updateTime() {
scope.time = dateFilter(new Date(), 'M/d/yy h:mm:ss a');
}
function updateLater() {
timeoutId = $timeout(function() {
updateTime();
updateLater();
}, 1000);
}
element.bind('$destroy', function() {
$timeout.cancel(timeoutId);
});
updateLater();
}
}
});
錯誤:
HTML1701: Unable to add dynamic content '<my-current-time></my-current-time>
'. A script attempted to inject dynamic content or elements previously modified dynamically that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content or explicitly create elements and attributes with a method such as createElement. For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.
File: index.html
看看這裏:http://stackoverflow.com/questions/ 12792383 /怎麼辦 - 你 - 得到 - 角JS對工作在一個窗口-8商店應用 –