-
Notifications
You must be signed in to change notification settings - Fork 77
Computed fields do not trigger digest cycle #327
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
Comments
Hmm... maybe js-data-angular can call |
Except The fields are re-computed in response to a It seems like it could cause an infinite loop of I change it so |
I've been meaning to have Resources emit a "change" event when the observer code detects changes in an object. This would enable you to do something like: app.controller('UserCtrl', function ($scope, $routeParams, User) {
// this gives you finer control over performance/when $digest loops happen
// rather than js-data-angular nuking your whole app with a bunch of $rootScope.$apply calls
User.on('change', $scope.$apply);
this.user = User.get($routeParams.id);
}); |
I'd only trigger The Also, it'd be nice if there was some config option that could enable calling |
Here's another problem, all the code for handling computed properties is in js-data, which is framework-agnostic and has no knowledge of Angular or This might help you: In your plunker you have: .controller('FooController', function ($scope, DS) {
$scope.user = DS.inject('user', {
id: 1,
firstName: 'Billy',
lastName: 'Joe'
});
DS.bindOne('user', 1, $scope, 'user');
}); Try changing it to: .controller('FooController', function ($scope, DS) {
$scope.user = DS.inject('user', {
id: 1,
firstName: 'Billy',
lastName: 'Joe'
});
DS.bindOne('user', 1, $scope, 'user', function () {
$scope.user.DSCompute();
});
}); It's not the most obvious thing, but it works. In fact, I could probably have js-data-angular do this for you...that would solve this problem. :) |
Awesome, that should work. Thanks! I think it'd be nice to also have a way to proxy bindOne like: .controller('FooController', function ($scope, User) {
User.find(1)
.then(function (user) {
myCtrl.complexModel.setUser(user);
user.DSBind($scope);
});
}); The example is kind of contrived yes. I'm just trying to show that a lot of the time the user won't be bound directly on Not an immediate need for it. I can ping back when it comes up. Still in the early stages of integrating js-data into our codebase. |
If I understand your complex model question correctly, then this should already work for you: // let's say the controllerAs is "FooCtrl"
.controller('FooController', function ($scope, User) {
User.find(1);
// "expr" can contain "." operators
User.bindOne(1, $scope, 'FooCtrl.complexModel.user');
}); |
Hmm... Yes that works. I think I mostly find it strange that |
Not a big deal. I'm happy with closing this out since the main issue has been resolved. |
Newly computed values are not reflected in the scope when they are updated. Try modifying the inputs on the Plunkr. The computed "fullName" is always a change behind. (I'm on Chrome 41 OSX 10.10)
http://plnkr.co/edit/SHJA4RPdn03mRbvGFwcy?p=preview
I expected this to just work, but I guess the behavior makes sense since it's hard for js-data to figure out which scopes depend on the computed value to trigger $digest cycles for. Is there a better way to do this? I was hoping I could replace some angular filters.
Btw, loving this library a lot.
The text was updated successfully, but these errors were encountered: