Angularjs-html-dom

提供:Dev Guides
移動先:案内検索

AngularJS-HTML DOM

次のディレクティブは、アプリケーションデータをHTML DOM要素の属性にバインドするために使用されます-

Sr.No. Name & Description
1

ng-disabled

特定のコントロールを無効にします。

2

ng-show

指定されたコントロールを表示します。

3

ng-hide

特定のコントロールを非表示にします。

4

ng-click

AngularJSクリックイベントを表します。

ng-disabledディレクティブ

ng-disabled属性をHTMLボタンに追加し、モデルに渡します。 モデルをチェックボックスにバインドし、バリエーションを確認します。

<input type = "checkbox" ng-model = "enableDisableButton">Disable Button
<button ng-disabled = "enableDisableButton">Click Me!</button>

ng-showディレクティブ

ng-show属性をHTMLボタンに追加し、モデルに渡します。 モデルをチェックボックスにバインドし、バリエーションを確認します。

<input type = "checkbox" ng-model = "showHide1">Show Button
<button ng-show = "showHide1">Click Me!</button>

ng-hideディレクティブ

ng-hide属性をHTMLボタンに追加し、モデルに渡します。 モデルをチェックボックスにバインドし、バリエーションを確認します。

<input type = "checkbox" ng-model = "showHide2">Hide Button
<button ng-hide = "showHide2">Click Me!</button>

ng-clickディレクティブ

ng-click属性をHTMLボタンに追加し、モデルを更新します。 モデルをHTMLにバインドし、バリエーションを確認します。

<p>Total click: {{ clickCounter }}</p>
<button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>

次の例は、上記のすべてのディレクティブの使用を示しています。

testAngularJS

<html>
   <head>
      <title>AngularJS HTML DOM</title>
   </head>

   <body>
      <h2>AngularJS Sample Application</h2>

      <div ng-app = "">
         <table border = "0">
            <tr>
               <td><input type = "checkbox" ng-model = "enableDisableButton">Disable Button</td>
               <td><button ng-disabled = "enableDisableButton">Click Me!</button></td>
            </tr>
            <tr>
               <td><input type = "checkbox" ng-model = "showHide1">Show Button</td>
               <td><button ng-show = "showHide1">Click Me!</button></td>
            </tr>
            <tr>
               <td><input type = "checkbox" ng-model = "showHide2">Hide Button</td>
               <td><button ng-hide = "showHide2">Click Me!</button></td>
            </tr>
            <tr>
               <td><p>Total click: {{ clickCounter }}</p></td>
               <td><button ng-click = "clickCounter = clickCounter + 1">Click Me!</button></td>
            </tr>
         </table>
      </div>

      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
      </script>

   </body>
</html>

出力

ファイル_testAngularJS_をWebブラウザーで開き、結果を確認します。