angular中不推荐混用JQuery的,原因呢问度娘。

其实这是一个比较蛋疼的问题,尤其是angular2.0,尽量不要在页面上写js,用ts写到模块里面去吧。。

汲取各位先人的智慧,还是列一下

window.onload(),$(document).ready()在angular中要怎么写:

1,html中直接写(请自行引用angular.js,否则2.0的页面中是不带有angular对象的)

<script src="lib/angular/angular.min.js" type="text/javascript"></script>
<script type="text/javascript">
angular.element(window).bind('load', function() {
alert('');
});
alert('');
</script>

不建议,直接在模板里面,写js代码。

2,在controller里面利用$on或者$watch

bookControllers.controller('bookctrl_test', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$on('$viewContentLoaded', function() {
alert('');
});
alert('');
}]);
bookControllers.controller('bookctrl_test1', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$watch('$viewContentLoaded', function() {
alert('');
});
alert('');
}]);

3,利用data-ng-init

<div ng-controller="test">
<div data-ng-init="load()" ></div>
</div>

注意:data-ng-init在controller里面才会启作用

bookControllers.controller('testInit', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.load = function() {
alert('code here');
}
}]);

好了,去学学TypeScript(ts)的语法吧!

angular中实现jQuery的Document Ready的更多相关文章

  1. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解

    1.(function($) {…})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){…} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...

  2. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详细讲解 ----转载

    1.(function($) {-})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){-} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...

  3. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别详解

    1.(function($) {…})(jQuery); 1).原理: 这实际上是匿名函数,如下: function(arg){…} 这就定义了一个匿名函数,参数为arg 而调用函数时,是在函数后面写 ...

  4. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别讲解

    1.(function($){...})(jQuery); (1).原理:       这实际上是匿名函数,如下: function(arg){...} 这就定义了一个匿名函数,参数为arg:而调用函 ...

  5. jQuery的document ready与 onload事件——你真的思考过吗?

    在进行实验和资料查询时,我遇到了几个关键问题: 1. window.onload到底是什么加载完触发? 2. body为什么会有onload事件? 3. 为什么是window.onload,而不是do ...

  6. jQuery之$(document).ready()使用介绍

    学习jQuery的第一件事是:如果你想要一个事件运行在你的页面上,你必须在$(document).ready()里调用这个事件 学习jQuery的第一件事是:如果你想要一个事件运行在你的页面上,你必须 ...

  7. jQuery:$(document).ready()用法

    jQuery:$(document).ready()用法 $(document).ready() 方法允许我们在文档完全加载完后执行函数;

  8. jsp中的javascript的$(document).ready( function() { $("#loginForm").validate()

    转自:https://bbs.csdn.net/topics/392459787?list=71147533 下面是jsp页面中的JavaScript代码 $(document).ready( fun ...

  9. jq方法中 $(window).load() 与 $(document).ready() 的区别

    通过自学进入了前端的行列,只知道在js中,一开头就写一个: window.onload = function(){ //doing sth} 然后所有的乱七八糟的代码全塞里面,大概知道window.o ...

随机推荐

  1. Github + Hexo 搭建博客

    服务加速 brew 加速 http://blog.suconghou.cn/post/homebrew-speedup/ github加速 http://www.selfrebuild.net/201 ...

  2. [翻译]Python with 语句

    With语句是什么? Python's with statement provides a very convenient way of dealing with the situation wher ...

  3. Hadoop Standalone and Pseudo Mode

    . Required Softwareyum install openssh-server rsync java-1.8.0-openjdk-devel . Setup Hostname/etc/ho ...

  4. sql 随机生成中文名字

    ,) )) -- 姓氏 ,) )) -- 名字 INSERT @fName VALUES ('赵'),('钱'),('孙'),('李'),('周'),('吴'),('郑'),('王'),('冯'),( ...

  5. React入门资源整理

    另外,附上我搜集的一些比较实用的学习资料,建议先看这些撸起来,再看什么乱七八糟的awsome系列. React入门资源整理 React项目新手指南 http://www.w3ctech.com/top ...

  6. A题笔记(14)

    Reverse Words in a String : http://oj.leetcode.com/problems/reverse-words-in-a-string/ 代码 : https:// ...

  7. ubuntu网络连接图标不显示

    sudo emacs /etc/NetworkManager/nm-system-settings.conf 将managed的值改为true,保存退出. sudo service network-m ...

  8. Visual C++ 打印编程技术-编程基础-获取打印机

    标准方法是用: EnumPrinters() 函数获取 #define PRINTER_ENUM_DEFAULT 0x00000001 #define PRINTER_ENUM_LOCAL 0x000 ...

  9. frame 第三节

    1.准备3个文件 main.html: <html> <head> <title>框架</title> </head> <frames ...

  10. 程序员的编辑器——VIM

    from:http://blog.chinaunix.net/uid-11278770-id-148579.html Chinaunix首页 | 论坛 | 认证专区 | 博客 登录 | 注册      ...