我想要实现的基本上是"on ng repeat finished rendering"处理程序.我能够检测到它何时完成,但我无法弄清楚如何从中触发一个功能.
检查小提琴:http://jsfiddle.net/paulocoelho/BsMqq/3/
JS
var module = angular.module('testApp', [])
.directive('onFinishRender', function () {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
element.ready(function () {
console.log("calling:"+attr.onFinishRender);
// CALL TEST HERE!
});
}
}
}
});
function myC($scope) {
$scope.ta = [1, 2, 3, 4, 5, 6];
function test() {
console.log("test executed");
}
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div ng-app="testApp" ng-controller="myC">
<p ng-repeat="t in ta" on-finish-render="test()">{{t}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
答案:来自finishmove的工作小提琴:http …
我有一个有两列的网站.我希望在使用jQuery时都有相同的高度.
我正试图获得徽标列高度.我有:
$(document).ready(function() {
alert($('#logo').height());
});?
Run Code Online (Sandbox Code Playgroud)
它不起作用.所以我改成了:
window.onload = function(){
alert($('#logo').height());
}
Run Code Online (Sandbox Code Playgroud)
它正在发挥作用.这里发生了什么?
对于局部视图,我想做一些我通常会做的JavaScript事情$(document).ready(function() {...}),例如将venet侦听器绑定到元素.我知道这对AngularJS和加载到"根"视图中的部分视图不起作用.
因此,我向监听$viewContentLoaded事件的控制器添加了一个监听器.调用侦听器的函数,因此事件被触发但在我看来好像是在呈现局部视图之前.当我在侦听器的函数中设置断点并使用firebug调试它时,我也没有看到元素,函数中的jquery选择也没有找到局部视图的元素.
这就是控制器的样子:
angular.module('docinvoiceClientAngularjsApp')
.controller('LoginController', function ($scope, $rootScope) {
$scope.$on('$viewContentLoaded', function(event) {
console.log("content loaded");
console.log($("#loginForm")); // breakpoint here
});
[...]
Run Code Online (Sandbox Code Playgroud)
我想我做错了,因为如果这是一个常见的错误,必须在stackoverflow上发布更多帖子.
当我使用ui-router和ui-view时,我会给你一个路由文件的摘录:
angular
.module('docinvoiceClientAngularjsApp', [
'ui.router',
'ngAnimate',
'ngCookies',
'ngResource',
'ngMessages',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function ($routeProvider, $stateProvider) {
$stateProvider
.state('login', {
url: '/',
templateUrl: 'components/login/loginView.html',
controller: 'LoginController'
})
.run(['$state', function ($state) {
$state.transitionTo('login');
}])
[...]
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.谢谢和亲切的问候
更新1:我将错误删除到以下用例:loginView.html如下所示:
<div id="loginContainer" style="width: 300px">
<form id="loginForm" ng-submit="login(credentials)" ng-if="session.token == undefined">
[...]
Run Code Online (Sandbox Code Playgroud)
一旦我ng-if …
我的jQuery .ready函数中的一些(几乎所有)代码也适用于调整窗口大小时,因为它的布局工作.但是,因为它是相同的代码,我怎么能"组合"这两个函数,以便我的代码不会重复(并且维护一团糟)?
谢谢!
我正在尝试在我打开的子窗口加载并准备好其文档时收到通知.这似乎不起作用:
win = window.open(href, 'test', 'width=300, height=400');
win.focus();
$(win.document).ready(function() {
// Ok, the function will reach here but if I try to manipulate the
// DOM it doesn't work unless I use breakpoints
$(this).contents().find("...").doStuff(); // nothing happens
});
Run Code Online (Sandbox Code Playgroud)
我需要做什么?
在cordova提供的示例app中cordova create ...,以下代码监听deviceready事件:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
Run Code Online (Sandbox Code Playgroud)
这很好,但是在我有时间听之前事件被解雇会发生什么?例如,使用以下内容替换示例应用程序(上面)中的代码:
bindEvents: function() {
setTimeout(function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
}, 2000)
},
Run Code Online (Sandbox Code Playgroud)
在此示例中,永远不会调用this.onDeviceReady.是否有更好,更可靠的方法来检查cordova是否准备好了?像这样的东西:
bindEvents: function() {
setTimeout(function () {
if (window.cordovaIsReady) {
this.onDeviceReady()
} else {
document.addEventListener('deviceready', this.onDeviceReady, false);
}
}, 2000)
},
Run Code Online (Sandbox Code Playgroud) 这是原位:一个包含html并使用jQuery libray和tabs的页面jQuery UI插件在单击某个选项卡时会加载另一个页面.问题是当页面/ html被加载/渲染时(让我们简化这个并说它只是做类似$("#myDiv").load(url);),就不会触发ready事件,因为当然"窗口"已经加载并触发了加载事件.这意味着我不想在页面的加载(部分加载)上执行任何jQuery操作.UI.tabs插件旨在将页面加载到其他选项卡中,我们可以假设其他页面可能包含自己的jQuery ...所以应该有一些方法来解决这个问题.
我可以想出解决这个问题的非常可怕的方法,例如在页面底部有一个脚本块被渲染(加载到div中),它可以完成我准备好时所做的所有事情(因为你可以假设浏览器)如果脚本块被命中,则已经呈现了页面).然而,这是非常糟糕的做法.有什么建议?
我有套接字已经声明套接字像这样:
serverAddr = InetAddress.getByName(this.ip);
socket = new Socket(serverAddr, port);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
Run Code Online (Sandbox Code Playgroud)
但是,以下不起作用.in.ready()总是返回false,如果删除,程序将冻结String message = in.readLine();
private void receive() {
try {
InputStreamReader isr = new InputStreamReader(socket.getInputStream());
System.out.println(isr.getEncoding());
BufferedReader in = new BufferedReader(isr);
if (in.ready()) {
String message = in.readLine();
if (message != null) {
if (listener != null) {
listener.receiveMessage(ip, message);
} else {
print("Client recieved: " + message);//
}
}
}
in.close();
} catch (Exception e) {
print("Error with input stream: …Run Code Online (Sandbox Code Playgroud) 使用jquery,我们可以将事件处理程序附加到页面中的元素,这是在document.ready()函数中完成的.现在我的困难是我在下载文件后有一些元素,比如稍后加载链接等(使用ajax请求).因此,这些新元素无法与我在页面中定义的处理程序绑定.有没有办法知道什么时候跟着ajax查询完成,然后在里面我可以绑定我的事件处理程序.
提前致谢
我正在做一个应用程序,Phonegap我正在使用自建幻灯片转换来更改页面.它的工作原理如下:
每个页面的div高度和宽度都是100%,所以如果我更改页面,我会将div右边的页面设置为当前活动的页面,然后向右滑动到左侧.
现在问题:滑动工作正常,但是在右边的内容div完全加载之前执行.因此右侧div滑动为空,只有几百毫秒后内容才会出现.
我试过了document.ready,但是因为我读过这个事件只在第一次DOM加载时执行.
有谁知道我可以等待DOM被完全呈现后,再次我操纵的DOM有Javascript?