「AngularJS」ngControllerディレクティブに変数と関数を使うサンプル
htmlコード
<script src="/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="personCtrl"> firstName: <input type="text" ng-model="firstName"><br> lastname: <input type="text" ng-model="lastName"><br> <br> detailName: {{fullName()}} </div>
javascriptコード
<script> var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.firstName = "A001"; $scope.lastName = "B002"; $scope.fullName = function() { return $scope.firstName + " " + $scope.lastName; } }); </script>