2016-09-23 4 views
0

Ich versuche, ein Tutorial für MEAN Stack beginnend mit Angular zu folgen und sogar der mitgelieferte Beispielcode wird nicht funktionieren. Der Code zeigt anstelle der Daten z. "{{created_buy}}" anstelle von "David". Ich bin neu in Angular so fühle ich mich wie ich offensichtlich etwas fehlen könnte ...AngularJS-Beispielcode zeigt Code nicht Daten

main.html:

<!--main.html--> 
<html> 
<head> 
    <title>Chirp</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script> 
    <script src="javascripts/chirpApp.js"></script> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="stylesheets/style.css"> 
</head> 
<body ng-app="chirpApp"> 
<div id='main' class="container" ng-controller="mainController"> 
    <div class="col-md-offset-2 col-md-8"> 
     <div class="clearfix"> 
      <form ng-Submit="post()"> 
       <input required type="text" class="form-control" placeholder="Your name" ng-model="newPost.created_by" /> 
       <textarea required class="form-control" maxlength="200" rows="3" placeholder="Say something" ng-model="newPost.text"></textarea> 
       <input class="btn submit-btn pull-right" type="submit" value="Chirp!" /> 
      </form> 
      <div id="post-stream"> 
       <h4>Chirp Feed</h4> 
       <div class="post" ng-repeat="post in posts | orderBy:'created_at':true" ng-class-odd="'odd'" ng-class-even="'even'"> 
        <p>{{post.text}}</p> 
        <small>Posted by @{{post.created_by}}</small> 
        <small class="pull-right">{{post.created_at | date:"h:mma 'on' MMM d, y"}}</small> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 
</body> 
</html> 

app.js:

//chirpApp.js 
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: ''}; 
    }; 
}); 

Antwort

0

Sie müssen die Bezug zu nehmen korrekte js Datei

<script src="javascripts/chirpApp.js"></script> 

aber Sie haben app.js erwähnt, so soll es sein

<script src="javascripts/app.js"></script> 

WORKING DEMO

+0

Die Antwort war sogar dümmer als das, aber das im Wesentlichen, was ich falsch gemacht habe, danke! War in Javascript nicht Javascripts – DAnsermino

+0

3 Buchstaben vs 1 Brief, macht es nur so viel banal. Beachten Sie, dass es ein Zeitlimit für die Markierung als Antwort gibt, was ich jetzt getan habe – DAnsermino