最近の更新

2016年10月12日水曜日

モジュール・コントローラを割り当てる方法(ng-app・ng-controller)

【目的】
AngularJSで、モジュール・コントローラを割り当てます(ng-app・ng-controller)。



【手順】
1.『AngularJS1.5.8のダウンロード方法』の手順で、AngularJS1.5.8をダウンロードしておきます。
2.『index.html』というファイルを作成。
3.『index.html』を以下の様に入力。
<!doctype html>
<html ng-app="mainModule">
    <head>
        <script src="angular.min.js"></script>
        <script>
            var mainModule = angular.module('mainModule',[]);
            var sampleController = function($scope) {
                $scope.name = 'あいうえお';
            };
            mainModule.controller('sampleController', ['$scope', sampleController]);
        </script>
    </head>
    <body ng-controller="sampleController">
        『{{name}}』さん、こんにちは。
    </body>
</html>

4.ダウンロードした『angular.min.js』と『index.html』を同一ディレクトリに配置します。
5.『index.html』をブラウザで開きます。
6.以下の様に表示されれば成功です。













































以上です。

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。

関連記事