Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding error in article-list, comment and article-actions components. #5

Open
yoomury opened this issue Dec 29, 2016 · 6 comments
Open

Comments

@yoomury
Copy link

yoomury commented Dec 29, 2016

Hi there, it seems that there is an issue with the article-list, comment and article-actions components. The binding values from the components are not accessible in the controllers. Any ideea of a solution?

@mirceananes
Copy link

The problem seems to be in the ArticleListCtrl 's constructor. The call to setListTo() is made with an undefined variable. Comment the line and the rest should work fine in Angular 1.5 (//this.setListTo(this.listConfig);)

@bstelljes
Copy link

bstelljes commented Mar 13, 2017

As a workaround I made a method outside of the constructor. There you have access to the bindings (like in the follow button component).

canModify() {
   if (this._User.current) {
    return (this._User.current.username === this.article.author.username);
  }
  else {
    return false;
  }
}

and remember to update your template:

<span ng-show="$ctrl.canModify()">

@RawleJuglal
Copy link

RawleJuglal commented Apr 24, 2017

I've been working https://thinkster.io/angularjs-es6-tutorial#compartmentalizing-page-functionality-into-components tutorial trying to prep myself to move to angular 2. I'm getting error TypeError: Cannot read property 'author' of undefined, which I think follows along with this issue. The article html populates with the article data before I try to add the canModify code above but does not once this step is added. This is my project if anyone wants to look and see if this just an error by me https://github.com/RawleJuglal/flow_news_app/tree/front_end

4/25/17 Edit:
Hey I thought I should come back and update that a stackoverflow user pointed out that my project was upgraded past Angular 1.5 and so how it is written works for 1.5 but must be taken out of the constructor and placed in the $onInit() function starting with 1.6. So for anyone searching for help, this could be a reason. But again, tutorial is correct if you are using 1.5.

@hht1230
Copy link

hht1230 commented May 23, 2017

RawleJuglal, thank you for that! In package.json, I changed
"angular": "^1.5.0-rc.2"
to
"angular": "~1.5.0"
and all works as advertised.

ssomnoremac pushed a commit to ssomnoremac/angularjs-realworld-example-app that referenced this issue Jun 15, 2017
@BalasubramaniM
Copy link

As @hht1230 said, Changing angular version from "^1.5.0-rc.2" to "~1.5.0" works perfectly and solves all the problem.

Also @bstelljes solution to the problem has also been resolved with this change. Thanks guys for the solution.

@gapablaza
Copy link

gapablaza commented Jul 24, 2017

To be able to use angular "1.6" (keeping "^1.5.0-rc.2" in package.json) in the constructor wrap the validation inside "$onInit" (thanks @RawleJuglal ) this way:

this.$onInit = () => {
  // The users can only edit/delete this article if they are the author
  if (User.current) {
    this.canModify = (User.current.username === this.article.author.username);
  } else {
    this.canModify = false;
  }
}

chrisxue815 added a commit to chrisxue815/angularjs-realworld-example-app that referenced this issue Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants