1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>AngularJS双向数据绑定</title> 6 <script type="text/javascript" src="../js/angular.min.js"></script> 7 </head> 8 <body> 9 <!--ng-app="myapp"定义了一个模块--> 10 <div ng-app="myapp" ng-controller="myctrl"> 11 <div> 12 <!--ng-model模型作用--> 13 <input type="text" name="name" ng-model="name"/> 14 </div> 15 <div> 16 <!--{{}}等价于ng-bind 用于数据显示--> 17 hello,{{name}} 18 </div> 19 </div> 20 </body> 21 <script type="text/javascript"> 22 //初始化myapp模块 23 var myapp = angular.module("myapp",[]); 24 //定义模块的控制器 25 //依赖注入,$scope作用域对象,操作当前作用域视图 26 myapp.controller("myctrl",["$scope",function($scope){ 27 //对模型进行初始化赋值 28 $scope.name = "你我他学习吧"; 29 }]) 30 </script> 31 </html>
原文地址:https://www.cnblogs.com/niwotaxuexiba/p/8119411.html
时间: 2024-10-26 02:52:44