AngularJS - ng-if example
HTML
<div ng-app="miniapp" ng-controller="Ctrl">
<div ng-if="beenAdded(id) == false">
<form id="formAddComment" name="formAddComment" novalidate>
<textarea id="taAddComment" name="taAddComment" placeholder="Add a comment.." ng-model="new_comment" ng-maxlength="1000" ng-required="true"></textarea>
<button type="button" ng-click="addComment(formAddComment)" ng-disabled="addCommentDisabled">Ok</button>
</form>
</div>
<button type="button" ng-click="showForm()">Show</button>
</div>
JavaScript
var $scope;
var app = angular.module('miniapp', []);
function Ctrl($scope) {
$scope.showDiv = true;
$scope.beenAdded = function(){
return $scope.showDiv;
};
$scope.showForm = function(){
$scope.showDiv = false;
}
$scope.addComment = function (formAddComment) {
console.log('valid');
if (formAddComment.$valid) {
console.log('valid');
}
}
};