页面并不总是识别 ng-if/new $scope 变量与 ES6 承诺
Page doesn't always recognize ng-if/new $scope variables with ES6 promises
奇怪的问题 -
因此,我 运行 加载用户配置文件的代码。在代码中,它会检查查看个人资料的人是否是 'friend'。如果是,它使用 NG-IF 并设置 $scope.button 以包含新文本。
但是 - 通常我需要刷新页面几次才能 Angular/http-server 看到这个。我可以在 console.log 中看到连接是正确的,但问题仍然存在。如果我不需要刷新,我会看到 "flickering" 并观察页面加载时范围的变化。
有什么办法可以避免这种情况吗?
我试过$scope.apply();。
(从 firebase 中提取数据)
由于 promise 来自 AngularJS 框架之外,框架不知道模型的变化,也不会更新 DOM。使用 $q.when
将外部承诺转换为 Angular 框架承诺。
var ref = x.child(userLoggedIn).child(allUsersArray[i].uid)
var refPromise = $q.when(ref.once('value'));
使用与 AngularJS 框架及其摘要循环正确集成的 $q 服务承诺。
$q.when
Wraps an object that might be a value or a (3rd party) then-able promise into a $q
promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.
我使用的是 Promises.all 并且 $q 似乎已经修复了这个行为。
在幕后,$q.all
对对象或数组中的每个承诺使用 $q.when
。这也会将外部承诺转换为 Angular 框架承诺。
奇怪的问题 -
因此,我 运行 加载用户配置文件的代码。在代码中,它会检查查看个人资料的人是否是 'friend'。如果是,它使用 NG-IF 并设置 $scope.button 以包含新文本。
但是 - 通常我需要刷新页面几次才能 Angular/http-server 看到这个。我可以在 console.log 中看到连接是正确的,但问题仍然存在。如果我不需要刷新,我会看到 "flickering" 并观察页面加载时范围的变化。
有什么办法可以避免这种情况吗?
我试过$scope.apply();。 (从 firebase 中提取数据)
由于 promise 来自 AngularJS 框架之外,框架不知道模型的变化,也不会更新 DOM。使用 $q.when
将外部承诺转换为 Angular 框架承诺。
var ref = x.child(userLoggedIn).child(allUsersArray[i].uid)
var refPromise = $q.when(ref.once('value'));
使用与 AngularJS 框架及其摘要循环正确集成的 $q 服务承诺。
$q.when
Wraps an object that might be a value or a (3rd party) then-able promise into a
$q
promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.
我使用的是 Promises.all 并且 $q 似乎已经修复了这个行为。
在幕后,$q.all
对对象或数组中的每个承诺使用 $q.when
。这也会将外部承诺转换为 Angular 框架承诺。