页面代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<script src="../vendor/angular/angular.js"></script>
<script src="../app/mycontroller.js"></script>
<body>
<div ng-app="myApp">
<div ng-controller="myController">
{{date}}
</div>
</div>
<!-- 当前页面调用 -->
<!-- <div ng-app="myApp" ng-controller="myCtrl">
名: <input type="text" ng-model="firstName"><br> 姓: <input type="text" ng-model="lastName"><br>
<br> 姓名: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script> -->
</body>
</html>
js:$apply的使用
var app = angular.module('myApp', []);
app.controller('myController', function($scope) {
console.log($scope)
$scope.date = new Date();
setInterval(function() {
$scope.$apply(function() {
$scope.date = new Date();
//...这里会执行脏检查,
})
}, 1000)
})