2
我有一個Cefsharp Chromium瀏覽器,並與Nancy建成一個WPF應用程序的本地端口上承載一個簡單的Web應用程序。我想用角與我的web應用程序,但我在努力改變角度範圍內的變量。麻煩連接cefsharp瀏覽器與南希託管角的web應用程序
直接角頁面上,一切都完美的作品。但是,當我嘗試跨越C#和JS之間的差距時,它部分失敗。當我火取消呼叫從C#中,警告窗口仍然顯示和report_type
值會出現在警告框來改變。但是,在ng-switch
中,沒有更新。這幾乎就像射擊從C#調用的時候,我沒有進入正確的範圍......但如果是這樣的話,在角範圍內的方法不應該是從C#調用。
在C#中,我把這:
private void GIS_Button_Click(object sender, RoutedEventArgs e)
{
this.report_browser.GetBrowser().MainFrame.ExecuteJavaScriptAsync("ext_switch_gis();");
}
所供應的網頁:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.switch_gis = function switch_gis() {
alert("begin switch gis");
$scope.report_type = "gis";
alert("end switch gis");
alert("report value is: " + $scope.report_type);
}
$scope.switch_bar = function switch_bar() {
alert("begin switch bar");
$scope.report_type = "bar";
alert("end switch bar");
alert("report value is: " + $scope.report_type);
}
$scope.mytest = function mytest(words) {
alert(words);
}
$scope.switch_bar();
});
function ext_switch_gis() {
var outside_scope = angular.element(document.getElementById('myAppDiv')).scope();
outside_scope.mytest("Beginning of external js call!");
outside_scope.switch_gis();
outside_scope.mytest("End of external js call!");
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<div id="myAppDiv" ng-app="myApp" ng-controller="myCtrl">
<div id="report_switch_div" ng-switch="report_type">
<div ng-switch-when="bar">
<h1>bar</h1>
</div>
<div ng-switch-when="gis">
<h1>gis</h1>
</div>
<div ng-switch-default>
<h1>Select a report type</h1>
</div>
</div>
<button ng-click="switch_gis()">gis test</button>
<button ng-click="switch_bar()">bar test</button>
</div>