Answer the question
In order to leave comments, you need to log in
Why can't I update data when receiving an event?
Hello!
Please tell me the problem.
There is a function that adds data to the database.
After adding, the $rootScope.$broadcast('db:change') event is dispatched:
$scope.addDb = function (name) {
NetFactory.addDb(name).then(
function (data) {
$scope.message = data;
}
);
$rootScope.$broadcast('db:change');
};
$rootScope.$on('db:change', function () {
NetFactory.getDbList().then(function (value) {
$scope.dbList = value;
});
});
Answer the question
In order to leave comments, you need to log in
Good afternoon!
Broadcast is called before the data is successfully added, so it should be moved to then. Try like this:
$scope.addDb = function (name) {
NetFactory.addDb(name).then(
function (data) {
$scope.message = data;
$rootScope.$broadcast('db:change');
}
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question