0

I am facing a string problem. I have placed a text input control and bind it with controller property and added a button input, but when i am trying to get the text input value on button click i am getting blank.

Controller

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>

2 Answers 2

1

Just add ng-controller attribute , like this:

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

Working example: http://jsfiddle.net/shPwB/1/

Sign up to request clarification or add additional context in comments.

4 Comments

@Ravi May be show us more of your code here or you can update my fiddle with your code
I will show you my code as i am using some SignalR code to get data from server so may be service part will not work.
@Ravi change this: $scope.comment like this: $scope.data.comment and it will work: jsfiddle.net/shPwB/4
@Ravi take a look at Egghead' bindings explanation: youtube.com/watch?v=Lx7ycjC8qjE
0

please update it as below

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

2 Comments

copy+pasted from my fiddle? :D
already defined data-ng-controller='chatController' at the top container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.