0
var app=angular.module('chirpApp',[]);

app.controller('mainController',function($scope){
    $scope.posts=[];
    $scope.newPost={created_by:'', text:'', created_at:''};

    $scope.post=function(){
        $scope.newPost.created_at = Date.now();
        $scope.posts.push($scope.newPost);
        $scope.newPost={created_by:'', text:'', created_at:''};
    }
});
<!DOCTYPE html>

<html>
    <head>
    <title>Chirp</title>
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <script src="javascripts/chirpApp.js"></script>
    </head>
    <body>
        <div id='main' ng-controller="mainController">
            <form ng-Submit="post()">
                <input required type="text" placeholder="Your name" ng-model="newPost.created_by"/>
                <textarea required maxlength="300" rows="3" placeholder="say something" ng-model="newPost.text" ></textarea>
                <input class="button" type="submit" value="Chirp!"/>
            </form>
            <div id="post-stream">
                <h4>Chirp Feed</h4>
                    <!-- to be polulated by angular-->
                     <div class='post' ng-repeat="post in posts | orderBy:'created_at':true" ng-class-odd="'odd'" ng-class-even="'even'">

                     <p>{{post.created_by}} says {{post.text}} at {{post.created_at}}</p>

                    </div>
            </div>
        </div>
    </body>
</html>

I am following a MEAN stack tut and I cant shows the name and text that submitted by the form. I'm new to web development and don't know why it is not working

1 Answer 1

1

hi can you try add this

<html ng-app="chirpApp">
Sign up to request clarification or add additional context in comments.

2 Comments

it works, thanks. but i still don't know why by adding ng-app into html tag makes it works. could you please explain why?
you can see the angular doc you have an explanation docs.angularjs.org/api/ng/directive/ngApp

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.