angularjs – 我如何正确使用typescript构造函数之外的angular $
发布时间:2020-12-17 17:49:39 所属栏目:安全 来源:网络整理
导读:我正在试图找出如何正确使用TypeScript的角度$timeout服务 – 这样当有人点击“登录”按钮时,我可以显示类似于闪屏的行为. interface INavigationController { username: string; password: string; loggedIn: boolean; ready: boolean; signIn(): void; sig
|
我正在试图找出如何正确使用TypeScript的角度$timeout服务 – 这样当有人点击“登录”按钮时,我可以显示类似于闪屏的行为.
interface INavigationController {
username: string;
password: string;
loggedIn: boolean;
ready: boolean;
signIn(): void;
signOut(): void;
}
class NavigationController implements INavigationController {
username: string;
password: string;
loggedIn: boolean;
ready: boolean;
static $inject = ['$timeout'];
constructor(private $timeout: ng.ITimeoutService) {
var vm = this;
vm.username = this.username;
vm.password = this.password;
vm.ready = true;
// The line below work just fine from within here - but i want the behavior
// when someone clicks a button,not directly like this.
// Remove vm.ready = true above,before...
//$timeout(function () { vm.ready = true;},2200);}
signIn() {
if (!this.username || !this.password) {
alert("You need to frickin enter som details,man!");
} else {
this.ready = false;
this.$timeout(function () {
this.ready = true;
},2200);
}
}
我还尝试将invokeApply?:boolean设置为true: this.$timeout(function () {
this.ready = true;
},2200,true);
– 没有任何成功…… 如果我是console.log(this.ready);从这个.$timeout(function()…它会在2200ms后显示为true,但似乎$apply()不适用? 如果有人可以启发我如何正确使用$timeout和其他类似的服务,我将不胜感激 – 最好使用样式指南我的目标是使用“controllerAs with vm” – John Papa 解决方法this.$timeout(()=> {
this.ready = true;
},2200);
如果你使用function(){}模式,你就无法访问它(这不是你期望的那个) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
