angularjs的控制器
发布时间:2020-12-17 08:43:53 所属栏目:安全 来源:网络整理
导读:使用ng-controller标签 !DOCTYPE htmlhtml lang="en"head meta charset="UTF-8" titleTitle/title/headbody div ng-app div ng-controller="firstController" input type="text" value="" ng-model="name" / {{name}} {{age}} /div /div script type="text/j
使用ng-controller标签
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div ng-app> <div ng-controller="firstController"> <input type="text" value="" ng-model="name" /> {{name}} {{age}} </div> </div> <script type="text/javascript" src="../vendor/angular/angularjs.js"></script> <script type="text/javascript" src="./app/index.js"></script> </body> </html> 实现类: var firstController = function ($scope) { //申明一个Model,$scope对象叫做作用域 $scope.name = '张三'; $scope.age = 20; }
多个控制器:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div ng-app> <div ng-controller="firstController"> <input type="text" value="" ng-model="name" /> <div ng-controller="secondController"> <input type="text" value="" ng-model="name" /> </div> </div> </div> <script type="text/javascript" src="../vendor/angular/angularjs.js"></script> <script type="text/javascript" src="./app/index.js"></script> </body> </html> 实现类:
var firstController = function ($scope) { //申明一个Model,$scope对象叫做作用域 $scope.name = '张三'; $scope.age = 20; } var secondController = function ($scope) { $scope.name = '李四'; }效果图:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |