码迷,mamicode.com
首页 > Web开发 > 详细

angularJS 第一天 使用模型与控制器绑定数据

时间:2017-06-22 00:23:26      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:bin   highlight   对象   static   rip   head   image   min   type   

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

    <div ng-app="myApp"  ng-controller="myCtrl">
        <p>名字 : <input type="text" ng-model="firstName" ng-bind="firstName"></p>
        <p>名字 : <input type="text" ng-model="lastName" ng-bind="lastName"></p>
        <span>{{firstName+" "+lastName}}</span>        
    </div>
    <script>

        var app = angular.module(‘myApp‘, []);
        app.controller(‘myCtrl‘, function ($scope) {
            $scope.firstName = "firstName";
            $scope.lastName = "lastName";

        });
    </script>

</body>
</html>

 

 ng-app="myApp" 指示这个区域是angrlar控制的 可在js中进行获取到这个模块 进行操作
 ng-controller="myCtrl" 用于控制 AngularJS 块的行为。
 $scope 接收控制对象 由angular传递过来
  ng-app指令定义了应用, ng-controller 定义了控制器。


效果:

技术分享

输入框文字出现变动时  所有绑定该模型的数据会进行相应的变动 

angularJS 第一天 使用模型与控制器绑定数据

标签:bin   highlight   对象   static   rip   head   image   min   type   

原文地址:http://www.cnblogs.com/ProDoctor/p/7062041.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!