我正面临一个字符串问题。我已经放置了一个文本输入控件并将其与控制器属性绑定并添加了一个按钮输入,但是当我尝试在按钮上获取文本输入值时,我将变为空白。
控制器
chat.controller('chatController', ['$scope', 'board', '$log', function ($scope, board, $log) {
$scope.Messages = [];
$scope.comment = '';
board.startBoard(function () {
board.loadAllMessages().then(function (messages) {
$scope.Messages = messages;
});
});
$scope.likeClick = function (isfromChild, message) {
$log.info(message);
};
$scope.dislikeClick = function (isfromChild, message) {
$log.info(message);
};
$scope.addComment = function () {
//HERE IS THIS PROBLEM
alert($scope.comment);
$scope.comment = '';
};
} ]);
Mark Up
<div style="margin-top: 10px">
<div class="input-group">
<input type="text" class="form-control" data-ng-model="comment" placeholder="write a comment..." />
<span class="input-group-btn">
<button class="btn btn-info" data-ng-click="addComment()" id="button1">
Post Commant</button></span>
</div>
</div>
答案 0 :(得分:1)
只需添加ng-controller
属性,如下所示:
<div style="margin-top: 10px" ng-controller="chatController">
答案 1 :(得分:0)
请按以下更新
<div style="margin-top: 10px" ng-controller="chatController">
<div class="input-group">
<input type="text" class="form-control" data-ng-model="comment" placeholder="write a comment..." />
<span class="input-group-btn">
<button class="btn btn-info" data-ng-click="addComment()" id="button1">
Post Commant</button></span>
</div>
</div>