夜の歌

プログラミング、音楽、本について緩く書いていきます。

月曜日の日記(7月29日)

昨日も会社でANgularJS。いよいよ大詰めに入ってきている感じ。31日で終わりだもんね。

先週の金曜日は、ng-repeatを使った際の、liタグのデータのアクセス方法を模索していた。 で分かったのがこれ。

index.html

<!DOCTYPE html>
<html ng-app>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
        <script src="script.js"></script>
    </head>
    <body>
        <div ng-controller="Controller">
            <p>The Dom is ready!</p>
            <ul>
                <li ng-repeat="test in tests">
                    {{test.key}}
                </li>
            </ul>
        </div>
    </body>
</html>

script.js

function Controller($scope) {
    $scope.tests = [{"key": "aho"}, {"key": "kaba"}];

    console.log($scope.tests[0]['key']);
    $scope.tests[0]['key'] = '';
}

srcipt.jsの5行目あたりのに書いてある通り。$scope.tests[0]['key']を使ってアクセス出来る。 日曜日にJavaScriptを復習したのが効いてるねw

なんていうか、言語の仕様がどうなっているか考えてプログラミングしたら、ちょっと書くのが早くなるかも。

まあ、明日だ!