zoukankan      html  css  js  c++  java
  • 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对象的函数,用于返回合成后的姓名。

  • 相关阅读:
    学习Swift -- 构造器(上)
    学习Swift -- 继承
    学习Swift -- 数组(Array)
    学习Swift--下标脚本
    学习Swift--方法
    学习Swift--属性
    Swift 类和结构体的简单认识
    dedecms代码研究二
    dedecms代码研究一
    PHP isset()与empty()的区别
  • 原文地址:https://www.cnblogs.com/allencxw/p/9074180.html
Copyright © 2011-2022 走看看