- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 angular $timeout 来显示元素 2 秒。它适用于 $scope 但我现在不知道如何将它与“this”关键字和“controller as ...”语法一起使用。
https://plnkr.co/edit/GPWRg4acYVrP1Ry00D7z?p=preview
angular.module("test", [])
.controller("testCtrl", function($scope, $timeout){
$scope.boo = false;
$scope.disappear = function(){
$scope.boo = true;
$timeout(function () {
$scope.boo = false;
}, 2000);
}
});
最佳答案
在通过 html 声明 Controller 时,请务必使用 controllerAs
模式,如 ng-controller="testCtrl as vm"
。因此 vm
基本上将具有 Controller 的别名,它将负责 object
通过 HTML 生成 this
上下文的值以进行绑定(bind)。
标记
<body ng-controller="testCtrl as vm">
<div>
<button ng-click="vm.disappear()">button</button>
<h1 ng-show="vm.boo">Hello Plunker!</h1>
</div>
</body>
代码
angular.module("test", [])
.controller("testCtrl", function($timeout) {
var vm = this;
vm.boo = false;
vm.disappear = function() {
vm.boo = true;
$timeout(function() {
vm.boo = false;
}, 2000);
}
});
此外,我还建议您将 this
上下文放在某个变量中,这样您就不会遇到与 this 相关的问题。引用this answer了解更多信息
关于javascript - 使用 angularjs $timeout "this"insted of $scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35661804/
读取日期文字很容易: (read-string "#inst \"2012\"") ;;; ⇒ #inst "2012-01-01T00:00:00.000-00:00" 如何将日期输
我有很多#inst 格式的日期,例如 (list #inst "2016-04-30T10:29:17.000-00:00" #inst "2016-03-24T12:13:12.000-
我正在写一个 R 包(供内部使用,永远不会在 CRAN 上)。我的一个函数调用包含 node.js 命令的 shell 脚本。我已将该文件放在 inst/node_script.sh 中,以便在安装包
好的,所以我的 .exe 给我一个零,所以我猜数据类型没有正确转换。对不起,我是 C++ 的新手,来自 C。每当我在 c 中遇到这个问题时,通常都会被截断,但我无法找出我做错了什么。 //shape.
当我使用 React 和 ReactDOM 展示一个非常基本的 Hello World 时,我遇到了一个奇怪的错误 Uncaught TypeError: inst.render is not a f
Valgrind 使用 mongocxx::instance inst{} 给我一个still reachable 记录; ==3014== 16,384 bytes in 1 blocks are
有时 self 可以表示类的实例,有时也可以表示类本身。那么,为什么我们不用inst 和klass 而不是self 呢?这不会让事情变得更容易吗? 现在怎么样了 class A: @classme
在问我之前,我承认这个问题的许多部分已经在其他堆栈中被触及,我已经阅读了 Hadley Wickham inst 和小插图部分,但我仍在努力解决我的警告。抱歉,如果这个问题有点啰嗦,我会尽量做到彻底。
Writing R Extensions手册状态: The data subdirectory is for data files, either to be made available via l
我有一些数据文件要与我正在创建的包一起分发。我已将文件放在 inst/extdata 中。我如何以及在哪里使用 roxygen2 记录这些文件? 最佳答案 我仍然不确定什么是最佳实践,但遵循 rawr
我需要使用 angular $timeout 来显示元素 2 秒。它适用于 $scope 但我现在不知道如何将它与“this”关键字和“controller as ...”语法一起使用。 https:
我的网站在所有现代桌面和移动浏览器上运行良好。某些功能不适用于智能手机上的 facebook 浏览器。这是一个问题,因为当有人在 Facebook 上分享链接时,我的网站运行不佳。一项不起作用的功能是
尽管安装了“jdk-13.0.1_windows-x64_bin”和“jre-8u231-windows-x64”,“eclipse-inst-win64.exe”仍无法打开。 我在 Windows
需要一些关于 jdbc 元数据的帮助。我正在使用 ResultsetMetaData 获取 Oracle10g 上表列的元数据。我正在使用 ojdbc14.jar。表 ID 中有一个字段声明为 Num
我的 inst/extdata 中有一个文件 helper.RData 文件,其中包含 我的包中的函数要使用的变量和数据集, 但并不意味着用户可以访问。 我使用以下命令在包的开头加载它: load(s
我有一个具有以下结构的 Web 应用程序: src + main +-+ java + resources + webapp +-+ WEB-INF + static 静态目录是服
我基本上有一个 jQuery Datepicker。日期选择器出现了,但它似乎不起作用,因为当选择一天时它什么也不做。它不起作用,并且也会选择上一个和下一个。 我收到“inst 未定义”错误 --脚本
在文档中,R 建议将原始数据文件(不是 Rdata 或 Rda)放置在 inst/extdata/ 从第一段开始:http://cran.r-project.org/doc/manuals/R-ext
我的添加产生了一些 View 比例问题。我通过制作 android:layout_width fill_parent insted wrap_content 解决了这个问题。 我应该注意的任何问题
您好,我是 java 脚本新手。 我想在我的 ASP.net 网页中实现此功能。我在项目中使用了一个单独的 .js 文件,并从 asp.net 网页的 header 部分调用它。 这是我要实现的功能。
我是一名优秀的程序员,十分优秀!