Reputation: 853
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>
Upvotes: 0
Views: 1127
Reputation: 3856
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>
Upvotes: 0
Reputation: 42166
Just add ng-controller
attribute , like this:
<div style="margin-top: 10px" ng-controller="chatController">
Working example: http://jsfiddle.net/shPwB/1/
Upvotes: 1