0

In the following snippet:

angular.module('myModule')
        .component('myComponent', {
            controller : [
                 MyComponentController
            ],
            bindings: {
               input: '<'
            }
        });

According to documentation - section "Components have a well-defined lifecycle" in order to monitor that the binding input has changed we could use $onChanges lifecycle method. I can't make it work.

Thi is how I am using it:

function MyComponentController() { self.$onChanges = function (changesObj){ // some code here } }

But the code doesn't even enter the fuction.

Amio.io
  • 20,677
  • 15
  • 82
  • 117
  • How are you trying to modify the binding? It'd help to see that part of the code too. – Joe Clay Apr 15 '16 at 10:29
  • @JoeClay I just got to this issue: https://github.com/angular/angular.js/issues/14030 It seems that I am doing it all well just the Angular v. 1.5.0 has a bug. It should be working in 1.5.3. I am gonna give it a try. – Amio.io Apr 15 '16 at 10:31
  • @JoeClay It was indeed the bug. But the release notes state that it was corrected in v.1.5.4. https://github.com/angular/angular.js/blob/master/CHANGELOG.md#154-graduated-sophistry-2016-04-14 – Amio.io Apr 15 '16 at 10:44
  • 1
    Ah, it's not a bug causing it then! The $onChanges hook actually wasn't added until version 1.5.3. The only hook that was available in 1.5.0 was $onInit. – Joe Clay Apr 15 '16 at 11:10
  • Good for you! I have updated the answer with your comment. If you post the answer I am gonna set your answer as correct. – Amio.io Apr 15 '16 at 11:18
  • Posted as an answer! – Joe Clay Apr 15 '16 at 11:25

2 Answers2

1

It was a bug corrected in version 1.5.4.

However, I am using version 1.5.3 and it is working. Strange...

Update

@JoeClay has noticed that it was not a bug at all. The $onChanges was added in version 1.5.3.

Amio.io
  • 20,677
  • 15
  • 82
  • 117
1

As we figured out in the comments, the issue was that the $onChanges hook (along with $onDestroy and $postLink) was not added until version 1.5.3 of Angular, and zatziky was using 1.5.0, which only implements the $onInit hook. Seems a bit strange for them to add such a big feature in a patch level release, but at least it was an easy fix.

Joe Clay
  • 33,401
  • 4
  • 85
  • 85