angular.js:domready中的等价物 [英] angular.js: equivalent of domReady
问题描述
警告:提前角新手
我在angular.js本页面code
I have this code in an angular.js page
<div class="clearfix" ng-controller="Controller">
<h1>Active Ideas
<button type="button" ng-click="search()">get Ideas</button></h1>
<hr>
然后我定义我的控制器:
and then I have defined my controller as:
function Controller($scope, $http) {
$scope.search = function(){...
和它工作正常。
我想执行搜索()函数当DOM准备好...
I'd like to execute search() function when the dom is ready...
我试着从$调用它(函数(){...但我不知道如何手动从我的控制器执行的方法
I tried calling it from a $(function() {... but I don't know how to manually execute a method from my controller
还与试图
$scope.$on('$viewContentLoaded', function() {
但不能使它工作(并没有找到太多的文档要么...)
But couldn't make it work (and couldn't find much documentation either...)
推荐答案
当你的控制器初始化,您应该执行搜索
。即。
You should execute search
when your Controller is initialized. i.e.
function Controller($scope, $http) {
$scope.search = function(){...};
$scope.search();
}
在角的依赖注入构建您的控制器,那么你知道你的看法被编译,链接,并准备初始化code。
When Angular's Dependency Injection constructs your controller then you know that the your view is compiled, linked, and ready for initialization code.
这篇关于angular.js:domready中的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!