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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I finally found. A script PhantomJS use javascript so we just have to call angularJS element like in javascript:
This is angular.element($("#someThing")).scope();
to get the scope.
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();
}
});
with an angularJS code like this :
$scope.getWidth = function() {
return 1600;
}
and an html page like this :
<div id="myDiv">
blabla
</div>