Q:

Angularjs databinding between factory and view

I'm having some trouble with databinding in AngularJS.
In short I'm trying to link a variable from my factory to my view (the $scope).
The factory (in my full implementation) listens to specific broadcasts and updates the variable, and the view should reflect this change, but it doesn't.
I managed to seperate the problem from much of the other code. The function the controller calls   (setTrue) is just a placeholder for some more difficult backend action.
When running the code, I would expect to see "true" written in the view. I have no idea why the view remains "false"?
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
<body ng-app="app">
    <div ng-controller="Fact">
        value: {{model}}<br/>
    </div>

    <script type="text/javascript">
        var app = angular.module("app", []);

        app.controller('Fact', ['$scope','Fact', function ($scope, Fact) {
          $scope.model = Fact.data;
          Fact.setTrue();
        }]);

        app.factory("Fact", function () {
            var Fact = {};
            Fact.data = false;

            Fact.setTrue = function () {
                Fact.data = true;
            };

            return Fact;
        });
    </script>
</body>

Plunker: http://plnkr.co/edit/IIq2H4gW1DBoe5zVPx0g
Can anybody tell me what I did wrong?
edit:
When I change the above code to have
$scope.model = Fact;

and
value: {{model.data}}

It suddenly works... but I don't like having to put my whole factory in my $scope.

A:

As you already know the following code snippet will work correctly. As you can see I am assigning the returned singleton to a scope value. From this I can thin call all of the returned methods from the factory on this new scope object.

angular.module("app", [])
  .controller('appCtrl', ['$scope', 'Fact',
    function($scope, Fact) {
      $scope.model = Fact;
      $scope.model.setTrue();
    }
  ]).factory("Fact", function() {
    var Fact = {};
    Fact.data = false;

    Fact.setTrue = function() {
      Fact.data = true;
    };

    return Fact;
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>

<div ng-app="app">
  <div ng-controller="appCtrl">
    value: {{model.data}}
    <br/>
  </div>
</div>

In your case I think this would be the correct way to accomplish what you are wanting. I assume you could think of other scenarios where a factory would have a large number of associated, and it would be useful that have access to the whole object in your controller.
In the following code snippet I have wrapped the Boolean value in an object and assigned like you were to the scope, but now any changes will be bound the the $scope.model object. 

angular.module("app", [])
  .controller('appCtrl', ['$scope', 'Fact',
    function($scope, Fact) {
      $scope.model = Fact.data
      Fact.setTrue();
      //$scope.model.setTrue();
    }
  ]).factory("Fact", function() {
    var Fact = {};
    Fact.data = {"value":false};

    Fact.setTrue = function() {
      Fact.data.value = true;
    };

    return Fact;
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<div ng-app="app">
  <div ng-controller="appCtrl">
    value: {{model.value}}
    <br/>
  </div>
</div>

However if you do not want to do it this way and are only wanting to assign the data value to the scope, you need to change the Fact factory before you assign the value to the scope or wrap it in an object that then will pass a reference instead of a value. It should be noted that in your code you were assigning a Boolean value to the $scope.model, however it is not bond to the Fact.data, adn thus any changes to Fact will not effect the model object.  

