Anh em xem thử tại sao cái đoạn code này thấy chạy rõ ràng mà khi copy về máy nó lại không chạy nhỉ??
Tại sao copy về máy lại không chạy?
Bạn đã gắn thư viện Angular vào chưa? Nếu ko chạy thì bạn cứ đưa hết source code offline của bạn lên đây xem sao.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>test</title>
<script src="https://code.angularjs.org/1.1.5/angular.js"></script>
<script>
window.requestAnimFrame = (function () {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (/* function */ callback, /* DOMElement */ element) {
window.setTimeout(callback, 1000 / 60);
};
})();
function myCtrl($scope) {
var keepgoing = true;
$scope.autoUpdateTimer = 30;
animate();
var currentSecond;
function animate() {
if (keepgoing) {
requestAnimFrame(animate);
draw();
}
}
function draw() {
if (!$scope.$$phase && currentSecond !== new Date().getSeconds()) {
$scope.$apply(function () {
$scope.autoUpdateTimer--;
});
currentSecond = new Date().getSeconds();
}
}
}
</script>
</head>
<body>
<div ng-controller='myCtrl'>
<p>{{autoUpdateTimer}}</p>
</div>
</body>
</html>
Sao thế nhệ??? Sao thế nhệ???Sao thế nhệ???Sao thế nhệ???
Thêm thuộc tính ng-app vào thẻ, thẻ được thêm sẽ đóng vai trò như Angular Container. SPA thì thêm vào thẻ “html” hay thẻ “body”
<html ng-app></html>
<body ng-app></body>
<div class="container" ng-app></div>
3 Likes
wow, cám ơn bạn nhé, quên cái ng-app

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?