我有控制器:
angular.module('app', [])
.controller('ctrl', ['$scope', function ($scope) {
$scope.daysPerMonth = new Date(year, month).getDate();
}]
);
和html:
<div ng-app>
<h1>How many days has month?</h1>
<input ng-model="month" type="text" placeholder="Set a month as number">
<input ng-model="year" type="text" placeholder="Set a year as number">
<p ng-if="year" ng-model="daysPerMonth">
In {{ month }} of {{ year }}, we have {{ daysPerMonth }} days.
</p>
</div>
为什么它不起作用?
答案 0 :(得分:1)
试试这个。你忘了添加ng-contoller和ng-app 我只是纠正你的错误。
var app = angular.module('app', []);
app.controller('ctrl',['$scope', function ($scope) {
//change your logic to compute ...
}]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<h1>How many days has month?</h1>
<input ng-model="month" type="text" placeholder="Set a month as number">
<input ng-model="year" type="text" placeholder="Set a year as number">
<p ng-if="year" >
In {{ month }} of {{ year }} ......
</p>
</div>
&#13;