0

I have this factory...

spa.factory("currentPageFactory", function() {
    var pageDefinition = {};
    pageDefinition.save = function(newPageDefinition) {
        pageDefinition.value = newPageDefinition;
    }
    pageDefinition.read = function() {
        return pageDefinition.value;
    }
    return pageDefinition;
});

...and this controller...

var pageDefinitionController = spa.controller("pageDefinitionController", ["currentPageFactory", function(currentPageFactory) {

        currentPageFactory.save("foobar");
}]);

I have tested using the .read() function I created in this factory by including a definition in the factory of pageDefinition.value. I could read the variable using the getter just fine. The problem seems to lie in the setter.

I'm calling these functions like this...

/*Setter Call Example*/
currentPageFactory.save("blah");

/*Getter Call Example*/
this.foobar = currentPageFactory.read();

What am I doing wrong? Why is the setter not working?

Allenph
  • 1,875
  • 27
  • 46
  • So what exactly doesn't work? The code is fine. – dfsq Jun 30 '15 at 08:48
  • Works fine here - http://jsfiddle.net/pqwq8qc6/ – CodingIntrigue Jun 30 '15 at 08:48
  • Really strange. It's not working on my site at all. The save function is included in a controller which is never put in an html attribute. I.E. the name of the controller that contains the save function call is never put in a "ng-controller" attribute on my HTML page. Is this the reason? – Allenph Jun 30 '15 at 09:03
  • 1
    @Allenph Probably. `pageDefinitionController` needs to be called from somewhere, either an `ng-route` or an `ng-controller` attribute – CodingIntrigue Jun 30 '15 at 09:18
  • That's not the problem either. I added it to `ng-controller` on the `` tag. – Allenph Jun 30 '15 at 09:28
  • I lied. That was indeed the problem. – Allenph Jun 30 '15 at 09:35

0 Answers0