day67—angularJS学习笔记控制器

转行学开发,代码100天——2018-05-22

angularJS通过控制器来控制数据流的应用。

ng-controller。

控制器中包含属性和函数,其参数引用通过 $scope来执行。

如下文的控制器

ng-controller="control"
<!DOCTYPE html>
<html>
<head>
    <title>angularJS 控制器</title>
    <script type="text/javascript" src="js/angular.min.js"></script>
    <script type="text/javascript">
        angular.module('myapp',[]).controller('control',function($scope){
            $scope.student = {
                firstName:'李',
                lastName:'四',
                fullName:function()
                {
                    var studentObject;
                    studentObject = $scope.student;
                    return studentObject.firstName+" "+studentObject.lastName;
                }
            };
        });
    </script>
</head>
<body ng-app="myapp" >
    <div ng-controller="control">
        Enter first name:<input type="text" ng-model="student.firstName"><br/>
        Enter last name :<input type="text" ng-model="student.lastName"><br/>
        You are enter:{{student.fullName()}}
    </div>
</body>
</html>
$scope.student是control控制器的对象属性,
firstName和lastName是$scope.student的属性,而fullName是
$scope.student对象的函数,用于返回合成后的姓名。

原文地址:https://www.cnblogs.com/allencxw/p/9074180.html