<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.js"></script>
<body ng-app="myApp">
<div ng-controller="toDoCtrl">
<div>
<hr>
<form class="form" name="commentForm" ng-submit="vm.submitCommentForm()">
<div class="form-group">
<label for="fieldBody">Comment:</label>
<textarea name="body" id="fieldBody" class="form-control" rows="3"
ng-change="vm.changeCommentForm()"
ng-model="vm.commentForm.body"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" ng-disabled="!vm.validCommentForm">Comment</button>
</div>
</form>
<hr>
</div>
</div>
脚本
var app = angular.module('myApp', []);
app.controller('toDoCtrl', function () {
var vm = this;
vm.validCommentForm = true;
})
&#34;评论&#34; vm.validCommentForm = true
时,按钮显示已禁用
同时,如果我硬编码ng-disabled=0
注释按钮出现工作,如假设。我出了什么问题?
答案 0 :(得分:3)
您使用的是controllerAs
方法,但未在视图中设置别名
尝试更改
<div ng-controller="toDoCtrl">
要
<div ng-controller="toDoCtrl as vm">