0

我面临一个字符串问题。我已经放置了一个文本输入控件并将其与控制器属性绑定并添加了一个按钮输入,但是当我试图在按钮单击时获取文本输入值时,我变得空白。

控制器

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 = ''; 
};
} ]);

标记

 <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>
4

2 回答 2

1

只需添加ng-controller属性,如下所示:

 <div style="margin-top: 10px"  ng-controller="chatController">

工作示例:http: //jsfiddle.net/shPwB/1/

于 2013-10-09T11:10:14.647 回答
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>
于 2013-10-09T11:47:04.977 回答