ng-hide ng-show clarification needed

I have two forms in my one page client side web app in angular js/javascript

I got two forms

<form class="simple-form" ng-submit="createuser()">
Log in As: 
  <input type="text" ng-model="name.username">
  <input type="submit"/>
</form>

The createuser() method is basically pushing an object into an array of objects.

$scope.createuser = function createuser() {
        var safer = angular.copy($scope.name);  
        $scope.users.push(safer);};

$scope.users = [
    {'username': 'John'},
    {'username': 'Dan'},
    {'username': 'Judy'}, 
    {'username': 'Michael'},
    {'username': 'Rebecca'},
    {'username': 'Macy'},
    {'username': 'Ross'}
    ];

I have another form that is a message container, basically I want the submit message to show only when a new user got created

<div class="message_container">
    <p ng-repeat="message in messages">
        {{message.post}}
    </p>
    <form class="post-form" ng-submit="postmessage()" ng-show="createuser()">
        <input type="text" ng-model="message.post">
        <input type="submit"/>
    </form>
</div>

I am trying to use ng-hide and ng-show for this. I am thinking that the form should show when the ng-submit="createuser()" The createuser() ended up creating some users blank ones because its a method and its looking for an expression. should I be using ng-show and ng-hide, maybe I should use something else instead.

Answers


ng-show and ng-hide need an expression to determine their status. You could set a flag to true when you create a new user:

$scope.createuser = function createuser() {
    var safer = angular.copy($scope.name);  
    $scope.users.push(safer);
    $scope.isNewUser = true;
}

<form class="post-form" ng-submit="postmessage()" ng-show="isNewUser">

Need Your Help

In Xcode 4 how do I add a remote GitHub repository to an existing local project?

git github xcode4 push

The Git integration in Xcode 4 is very welcome however it seems to be a bit flaky when it comes to dealing with remote repositories.

Data transmission through USB

c++ embedded visual-c++

I want to develop code to transmit data from system to PIC through USB.