javascript - My Submitpost function isn't working -
first time using angularjs , i'm following angularjs reddit clone tutorial , don't know went wrong. when click submit button nothing happens. https://github.com/eibonic/angularjs-reddit/tree/master/app
this nav.js controller
'use strict'; app.controller('navctrl', function ($scope, $location, post, auth) { $scope.post = {url: 'http://', title: ''}; $scope.submitpost = function () { post.create($scope.post).then(function (ref) { $scope.post = {url: 'http://', title: ''}; $location.path('/posts/' + ref.name()); }); }; });
this nav.html view file.
<nav class="navbar navbar-default" role="navigation"> <!-- brand , toggle grouped better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">ang-news</a> </div> <!-- collect nav links, forms, , other content toggling --> <div ng-controller="navctrl" class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <form class="navbar-form navbar-left" role="search" ng-submit="submitpost()"> <div class="form-group"> <input type="text" class="form-control" placeholder="title" ng-model="post.title"> </div> <div class="form-group"> <input type="text" class="form-control" placeholder="link" ng-model="post.url"> </div> <button type="submit" class="btn btn-default">submit</button> </form> </div><!-- /.navbar-collapse --> </nav>
i took @ github project linked, there 2 issues; found both of them running project , opening debug console in chrome.
unknown provider: authprovider <- auth <- navctrl
in english, means attempted inject auth
provider (which doesn't exist) dependency in navctrl. on line 3 of nav.js. aren't using auth service yet, removing function declaration fixes it. should this:
app.controller('navctrl', function ($scope, $location, post)
once point in tutorial create auth provider you'll able inject here.
the second error get http://localhost:9000/scrips/controllers/postview.js 404
this means html attempted load postview.js script, couldn't find it. turns out there typo in index.html on line 89 when loading script. should http://localhost:9000/scripts/controllers/postview.js
(missing 't' in 'scripts')
after making 2 changes seems working fine now.
Comments
Post a Comment