我正在尝试将我的应用程序的输入文本框设置为禁用,直到从右侧单击用户名。我尝试ng-disabled
在输入框上使用,但在单击链接之前无法将其设置为禁用。
我认为用户列表中的用户名需要设置一个模型来检查状态,但这似乎不起作用。
用户列表指令
chatApp.directive("usersList", function(){
return {
restrict: "E",
scope: false,
template: "<p>Users</p>"+
"<ol class='list-unstyled animated fadeInDown'>"+
"<li ng-repeat='user in users'>"+
"<a class='users' ng-click='toggleDetails(message)'>{{user.name | uppercase}}</a>"+
"</li>"+
"</ol>"
,
link: function(scope) {
scope.toggleDetails = function(message)
{
angular.forEach(scope.messages, function(value, key){
if(message != value)
value.showDetails = false;
});
message.showDetails = !message.showDetails;
}
}
}
});
在用户单击用户指令中的链接之前,需要禁用带有文本输入的消息指令
chatApp.directive("messagesList", function(){
return {
restrict: "E",
scope: false,
template: "<div class='panel panel-primary'>"+
"<div class='panel-heading'>"+
"<span class='glyphicon glyphicon-comment'></span> Chat</div>"+
"<div class='panel-body body-panel'>"+
"<ol class='list-unstyled'>"+
"<li ng-repeat='message in messages | filter:{showDetails:true}'>"+
"<p>{{message.user | uppercase}}: {{message.message}}</p>"+
"<p>Matt: {{response}}</p>"+
"<span ng-repeat='message in messages | filter:{showDetails:true}'>{{message.user | uppercase}}:</span>{{autoresponse}}"+
"</li>"+
"</ol>"+
"</div>"+
"<div class='panel-footer clearfix'>"+
"<form name='form'>"+
"<input type='text' name='message' ng-model='chat' class='form-control' />"+
"<span class='col-lg-6 col-lg-offset-3 col-md-6 col-md-offset-3 col-xs-12' style='margin-top: 10px'>"+
"<button class='btn btn-warning btn-lg btn-block' id='btn-chat' ng-click='sendMessage(messages)' ng-disabled='!form.message.$dirty'>Send</button>"+
"</span>"+
"</form>"+
"</div>"+
"</div>"
};
});
当前plunker:LINK