angularJS(3)

來源:互聯網
上載者:User

標籤:clear   blog   html 表單   輸入   type   複製   名稱   pyc   技術分享   

一.angularJs的指令模型ng-model指令

ng-model 指令 綁定 HTML 元素 到應用程式資料。 
為應用程式資料提供類型驗證(number、email、required)。
為應用程式資料提供狀態。
為 HTML 元素提供 CSS 類。
綁定 HTML 元素到 HTML 表單。

<div ng-app="myapp" ng-controller="mycc">    名字: <input ng-model="name"></div><script>var app = angular.module(‘myapp‘, []);app.controller(‘mycc‘, function($scope) {    $scope.name = “宋小寶";});</script>

二.angularJs的指令模型ng-model指令:雙向繫結

在修改輸入欄位的值時, AngularJS 屬性的值也將修改:

<div ng-app="myapp" ng-controller="mycc">    名字: <input ng-model="name">    <h1>你輸入的名稱是:{{name}}</h1></div><script>var app = angular.module(‘myapp‘, []);app.controller(‘mycc‘, function($scope) {    $scope.name = “宋小寶";});</script>

三.angularJs的應用

<div ng-app="myapp" ng-controller="myctrl">    姓:<input type="text" ng-model="xing"><br>        名:<input type="text" ng-model="ming">        <h1>你的姓名是:{{xing+""+ming}}</h1></div><script>    var app=angular.module("myapp",[]);    app.controller("myctrl",function($scope){         $scope.xing="宋";         $scope.ming="小寶";    })</script>

執行個體說明:
模組(m):var app = angular.module(‘myApp‘, []); 
控制器(c):app.controller("myctrl",function($scope){   })
視圖(v):就是html地區

四.angularJs模型

ng-model 指令用於繫結應用程式資料到 HTML 控制器(input, select, textarea)的值。 
ng-model 指令可以將輸入欄位的值與 AngularJS 建立的變數綁定

<div ng-app="myApp" ng-controller="myCtrl">    名字: <input ng-model="name"></div><script>var app = angular.module(‘myApp‘, []);app.controller(‘myCtrl‘, function($scope) {    $scope.name = “花果山美猴王";});</script>

angularJS(3)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.