Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinayak Patil committed Feb 28, 2014
1 parent b3bc349 commit 2e00aa7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions demo/angularBlog/app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Controllers */

angular.module('myApp.controllers', ['myApp.services']).
run(function($rootScope){
run(function($rootScope) {
$rootScope.categories = [
'backbone',
'angular',
Expand All @@ -27,24 +27,24 @@ controller('PostController', function($scope, blogAPI, $routeParams) {
post.comments = post.comments.split(",");
$scope.post = post;
}, function(errorMsg) {
cosole.error(errorMsg);d87
cosole.error(errorMsg);
});

$scope.toggleComments = function(){
$scope.showComments = !$scope.showComments;
};

}).
controller('CategoryController', function($scope, blogAPI, $routeParams){
controller('CategoryController', function($scope, blogAPI, $routeParams) {
$scope.category = $routeParams.category;
blogAPI.getPostsByCategory($routeParams.category).then(function(posts){
blogAPI.getPostsByCategory($routeParams.category).then(function(posts) {
$scope.posts = posts;
}, function(errorMsg) {
cosole.error(errorMsg);
});
}).
controller('FeedbackController', function($scope){
$scope.submitForm = function(){
controller('FeedbackController', function($scope) {
$scope.submitForm = function() {
console.log("in Feedback form submit handler");
};
});
11 changes: 6 additions & 5 deletions demo/angularBlog/app/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ angular.module('myApp.services', [])
return deferred.promise;
};

this.getPostsByCategory = function(category){
this.getPostsByCategory = function(category) {
var deferred = $q.defer();
if (_posts) {
deferred.resolve(_filterByCategory(category));
} else{
} else {
this.getPosts().then(function() {
deferred.resolve(_filterByCategory(category));
}, function() {
Expand All @@ -52,6 +52,7 @@ angular.module('myApp.services', [])
};

/* Helper functions */

function _findPost(id) {
var index, length, post;
for (index = 0, length = _posts.length; index < length; index++) {
Expand All @@ -63,10 +64,10 @@ angular.module('myApp.services', [])
return post;
}

function _filterByCategory(category){
return _posts.filter(function(post){
function _filterByCategory(category) {
return _posts.filter(function(post) {
return post.category === category;
})
});
}
})
.value('version', '0.1');
1 change: 0 additions & 1 deletion demo/angularBlog/app/partials/category.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<h2>Posts for category: <span class="label label-default">{{category | uppercase}}</span></h2>
<ul class="media-list col-md-12">
<excerpt ng-repeat="post in posts|filter:search" post="post"/>

</ul>
<h3 ng-if="posts.length === 0"> No posts available</h3>

Expand Down
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ <h2>How does angular work ?</h2>
</a>
<p>MVC big picture</p>
</section>

<section>
<a href="#">
<img src="images/databinding.png" alt="Two way data binding">
</a>
<p>Two way data binding</p>
</section>
</section><!-- How angular js works end -->

<!-- Controllers and Scope beginning -->
Expand Down

0 comments on commit 2e00aa7

Please sign in to comment.