Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Show article from category mean.js #1663

Closed
mskinho opened this issue Dec 2, 2016 · 8 comments
Closed

Show article from category mean.js #1663

mskinho opened this issue Dec 2, 2016 · 8 comments

Comments

@mskinho
Copy link

mskinho commented Dec 2, 2016

Link Menu

<a ui-sref="articles.list-nav({category: category.name})">
  {{ category.name }}</a>

Route Client:

.state('articles.list-nav', {
        url: '/:category/articles',
        templateUrl: 'modules/articles/views/list-articles-scategory.client.view.html',
        controller: 'ArticlesController'
      })

List Article Category:

<a class="md-12-line" ng-repeat="article in getArticles(category.id) ">
Controller Client:

$scope.getAticles = function(category){
             var result = [];
             for(var i = 0 ; i < $scope.articles.length ; i++){
                 if(category === $scope.articless[i].category){
                     result.push($scope.articles[i]);
                 }
             }
             console.log(category);
             return result;
         };

I tried the other way:

Controller Client:

$scope.subCat = $stateParams.subcategoria;
List Article Category:

<a class="md-12-line" ng-repeat="article in article | Filter: {(category: category.id)} ">
But not working anyway, can I help me?

@mleanos
Copy link
Member

mleanos commented Dec 2, 2016

@mskinho I don't understand what last two examples you provided in your description.

However, the one thing that jumps out at me is the referencing of category in your view/template. Where are you setting this value in your Angular controller? You must retrieve it from the router using $stateParams.category and set it to a scope variable (e.g. $scope.category = $stateParams.category;.

In addition, it appears that categories reside in your Article data. The way that you're checking for equality in your getArticles method, is just checking the value of the category field in your Article schema. However, in your view you pass in category.id to this method; this would only work if your category scope variable is a populated data set (i.e. has the id property in this case), and in your $scope.articles variable the category field is just a reference to it's id.

If you could clarify some of this, that would help in understanding your issue.

@mleanos mleanos self-assigned this Dec 2, 2016
@mleanos mleanos added this to the q milestone Dec 2, 2016
@mskinho
Copy link
Author

mskinho commented Dec 3, 2016

mleanos thanks for your help.
I'm using $scope.category = $stateParams.category;.
I not expained in the right way.
I need show article for each categoryID.
Ex:
menu IT: all article from category IT
menu marketing: All article from category Marketing

Thanks for help.

@mleanos
Copy link
Member

mleanos commented Dec 3, 2016

@mskinho What does the data in $scope.articles[i].category?

Is it just the Category ID? something like: { category: 'some-mongoose-id' ..}
OR
Does it have the populated data of the Category?: { id: 'some-mongoose-id', name: 'some-category-name'.... }

Can you describe how this is not working? Are you getting console errors? Or is it just not finding any articles for the provided Category?

@mskinho
Copy link
Author

mskinho commented Dec 5, 2016

@mleanos I using this method in: $scope.getAticles = function(category){
var result = [];
for(var i = 0 ; i < $scope.articles.length ; i++){
if(category === $scope.articless[i].category){
result.push($scope.articles[i]);
}
}
console.log(category);
return result;
};

Like menu dropdown it's work this way, but for display in other page not work.
I get the list url normally, exemplo: http://127.0.0.1:3000/articles/content-marketing/articles
But not filter 'article' from category 'content-marketing'

@mskinho
Copy link
Author

mskinho commented Dec 5, 2016

@mleanos
Copy link
Member

mleanos commented Dec 6, 2016

if(category === $scope.articless[i].category){

@mskinho In that line, in your example code, what is $scope.articles[i].category? Is it the populated data of Category? Or is it the "_id" of Category? It appears that "category" that you are passing this $scope.getArticles method is the "_id".

Can you describe in more detail how it's not working? Do you see any console logs?

BTW: the repo link you provided in your last comment, doesn't work. It goes to a 404 page. It's most likely a private repo.

@mskinho
Copy link
Author

mskinho commented Dec 6, 2016

Update link https://github.com/K-M-B/mean.js-support-module/blob/master/modules/support/client/views/support.issues.client.view.html
I passed _id in category, in console log give category "Undefined"

@mskinho
Copy link
Author

mskinho commented Dec 6, 2016

I found exemplo That works similarly that I need. http://plnkr.co/edit/yNOIlgBK2inFy1FkFsKk?p=preview
I just can not replace '_.find'

Do you have any exemplo that display article from category or similar, using struture mean.js?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants