2016-09-12 9 views
-1

MEANスタックを使用してredditクローンを作成する方法を示すLinksterのオンラインチュートリアルをフォローしています。 (https://thinkster.io/mean-stack-tutorial#angular-routing

私はすべてを試してみましたが、何も動作していないようです。どのようなアイデアが間違っている?すべてのヘルプ/アイデアが評価されています:)

を-----のindex.html ----------------

<html> 
    <head> 
     <title>Welcome to FlapperNews!</title> 
    <link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.min.js"></script> 

    <script src="app.js"></script> 
    <style> .glyphicon-thumbs-up { cursor:pointer } </style> 
</head> 
<body ng-app="flapperNews" ng-controller="MainCtrl"> 
    <div class="row"> 
     <div class="col-md-6 col-md-offset-3"> 
      <ui-view></ui-view> 
     </div> 
    </div> 

    <script type="text/ng-template" id="/home.html"> 
     <div class="page-header"> 
       <h1>FlapperNews</h1> 
     </div> 
      <div ng-repeat="post in posts | orderBy: '-upvotes'"> 
       <span class="glyphicon glyphicon-thumbs-up" ng-click="incrementUpvotes(post)"></span> 
       <span style="font-size:20px; margin-left:10px;"> 
       <a ng-show="post.link" href="{{post.link}}"> 
        {{post.title}} 
       </a> 
       <span ng-hide="post.link"> 
        {{post.title}} 
       </span> 
       -upvotes: {{post.upvotes}} 
      </div> 
      <form ng-submit="addPost()" 
      style="margin-top:30px;"> 
       <h3>Add a new post</h3> 

       <div class="form-group"> 
        <input type="text" class="form-control" placeholder="title" ng-model="title"></input> 
       </div> 
       <div class="form-group"> 
        <input type="text" class="form-control" placeholder="Link" ng-model="link"></input> 
       </div> 
       <button type="submit" class="btn btn-primary">Post</button> 
      </form> 
    </script> 
</body> 
</html> 

---- app.js ----------------

var app = angular.module('flapperNews', ['ui-router']); 
app.config([ 
'$stateProvider', 
'$urlRouterProvider', 
    function($stateProvider, $urlRouterProvider){ 

$stateProvider 
    .state ('home', { 
    url: "/home", 
    templateUrl: "/home.html", 
    controller: 'MainCtrl' 
    }); 

    // .state('posts', { 
    // url: '/posts/{id}', 
    // templateUrl: '/posts.html', 
    // controller: 'PostsCtrl' 
    // }); 

    $urlRouterProvider.otherwise('home'); 
    }]) 

app.factory('posts', [function(){ 
    var o = { 
    posts: [{title: 'hello post1', link: '', upvotes: 0 }] 
    }; 
    return o; 
}]) 

app.controller('MainCtrl', [ 
'$scope', 
'posts', 
function($scope, posts){ 
    $scope.test = 'Hello world!'; 

    $scope.posts = posts.posts; 

$scope.addPost = function(){ 
     if(!$scope.title || $scope.title === '') { return; } 
     $scope.posts.push({ 
     title: $scope.title, 
     link: $scope.link, 
     upvotes: 0}); 
    $scope.title = ''; 
    $scope.link = ''; 
    } 

    $scope.incrementUpvotes = function(post) { 
    post.upvotes += 1; 
    } 
}]); 

答えて

2

var app = angular.module('flapperNews', ['ui.router']);代わり

+0

var app = angular.module('flapperNews', ['ui-router']);のおかげで多くのことをお試しください!出来た。しかし、私はそれを取得しない - 何が間違っていたのですか? –

+0

モジュール名はui-routerですが、ui-routerではなくui.routerを注入する必要があります – Lasith

関連する問題