LoginSignup
6
7

More than 5 years have passed since last update.

AngularJSでHello World

Posted at
  • Angular 1.5.3で確認

HTML

<!DOCTYPE html>

<html ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>hello world</title>
    <script src="./angular.min.js"></script>
    <script src="./controller.js"></script>
</head>
<body>
    <div ng-controller="HelloController">
        <input type="text" ng-model="greeting.text" value="{{greeting.text}}">
        <p>{{greeting.text}}</p>
    </div>
</body>
</html>
  • ng-app でモジュール定義
  • ng-controller でコントローラの適用範囲を定義
  • ng-model フォームコントロールとモデルのバインディング
  • {{}} でモデルの参照

JavaScript

// コントローラとして呼び出されるメソッドの定義
function HelloController($scope) {
    $scope.greeting = { text : "hello world" };
}
// 'app'モジュールにHelloControllerコントローラの登録
angular.module('app', [])
    .controller('HelloController', HelloController);
  • コントローラで読みだされる Functionの定義
  • angularmodule で 'app' にコントローラの登録
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7