使用phantomJS angularJS功能 [英] Using angularJS function in phantomJS

查看:104
本文介绍了使用phantomJS angularJS功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索,我什么也没找到。
我有出现,或者从我的HTML页面中消失元素的脚本angularJS。
我用一个脚本phantomJS访问到HTML页面,并做一些东西。但是,我可以使用 $范围或我的角度脚本的功能在我的幽灵脚本?
我知道我可以使用jQuery但角我不知道。

I searched on the net and I found nothing. I have a script angularJS which appear or disappear element from my html page. I use a phantomJS script to access to the html page and do some stuffs. But Can I use the $scope or the functions of my angular script in my phantom script ? I know that I can use jQuery but angular i don't know.

推荐答案

我终于找到了。脚本PhantomJS使用JavaScript,所以我们只需要调用angularJS元素就像在JavaScript:

I finally found. A script PhantomJS use javascript so we just have to call angularJS element like in javascript:

这是 angular.element($(#SOMETHING))范围(); 来获取范围

所以我们可以有phantomJS的这个例子:

So we can have this example of phantomJS :

page.open('http://www.google.com', function (status) {
    if ('success' !== status) {
        console.log("Error");
    } else {
        page.evaluate(function() {          
            angular.element($("#someThing")).scope().aFunctionInTheScope();
            var scope = angular.element($("#myDiv")).scope();
            var width = scope.getWidth();
        });
        phantom.exit();
    }
});

与angularJS code是这样的:

with an angularJS code like this :

$scope.getWidth = function() {
     return 1600;
}

和一个像这样的html页面:

and an html page like this :

<div id="myDiv">
    blabla
</div>

这篇关于使用phantomJS angularJS功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆