controller---逻辑核心、大段代码
$scope---angular的作用域(所有的Angular里面的东西,都在scope上)
<!DOCTYPE html>
<html ng-app="test">
<head lang="en">
<meta charset="UTF-8">
<title>></title>
<script src="angular-1.7.2/angular.min.js"></script>
<script>
let mod = angular.module('test',[]);
mod.controller('controlname',function($scope){
//作用域 $scope
$scope.a = 0; $scope.b = 0;
$scope.int = function(str){
return parseInt(str);
}
})
</script>
</head>
<body ng-controller="controlname">
<input type="text" ng-model="a"/>
<input type="text" ng-model="b"/>
<!--因为angular和js不互通,所以此处parseInt不起作用 {{parseInt(a)+ parseInt(b) }}-->
{{ int(a) + int(b) }}
</body>
</html>
网友评论