Angularjs-expressions

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

AngularJS-式

式は、アプリケーションデータをHTMLにバインドするために使用されます。 式は、\ {\ {expression}}のように二重中括弧内に記述されます。 式は、ngbindディレクティブと同様に動作します。 AngularJS式は純粋なJavaScript式であり、使用されているデータを出力します。

数字を使う

<p>Expense on Books : {{cost *quantity}} Rs</p>

文字列を使用する

<p>Hello {{student.firstname + " " + student.lastname}}!</p>

オブジェクトを使用する

<p>Roll No: {{student.rollno}}</p>

配列を使用する

<p>Marks(Math): {{marks[3]}}</p>

次の例は、上記のすべての式の使用を示しています-

testAngularJS

<html>
   <head>
      <title>AngularJS Expressions</title>
   </head>

   <body>
      <h1>Sample Application</h1>

      <div ng-app = "" ng-init = "quantity = 1;cost = 30;
         student = {firstname:'Mahesh',lastname:'Parashar',rollno:101};
         marks = [80,90,75,73,60]">
         <p>Hello {{student.firstname + " " + student.lastname}}!</p>
         <p>Expense on Books : {{cost* quantity}} Rs</p>
         <p>Roll No: {{student.rollno}}</p>
         <p>Marks(Math): {{marks[3]}}</p>
      </div>

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

   </body>
</html>

出力

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