[英]AngularJS not working in Xamarin Android Webview
I'm trying to load page content to webview, page content reference AngularJS, and Angular Material. 我正在尝试将页面内容加载到webview,页面内容参考AngularJS和Angular Material。 When I run it in debug on my computer, it works fine via an Android emulator.
当我在计算机上的调试中运行它时,它可以通过Android模拟器正常运行。 But when I install it on my smartphone, it does not work.
但是,当我将其安装在智能手机上时,它将无法工作。 It would seem it doesn't know the JavaScript libraries.
似乎不知道JavaScript库。 Many thanks for your help.
非常感谢您的帮助。
MainActivity.cs: MainActivity.cs:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
var webView = FindViewById<WebView>(Resource.Id.webView);
webView.Settings.JavaScriptEnabled = true;
//webView.Settings.CacheMode = CacheModes.Normal;
webView.Settings.DomStorageEnabled = true;
webView.Settings.SetSupportMultipleWindows(true);
webView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
webView.Settings.AllowContentAccess = true;
webView.Settings.AllowFileAccess = true;
webView.Settings.AllowFileAccessFromFileURLs = true;
// webView.SetWebChromeClient(new WebChromeClient());
webView.SetWebViewClient(new WebViewClient());
webView.LoadUrl("file:///android_asset/Content/List.html");
}
List.html: List.html:
<html>
<head>
<title>Angular JS Directive</title>
<link href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.css" rel="stylesheet"></link>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"></link>
<style type="text/css">
.listdemoListControls md-divider {
margin-top: 10px;
margin-bottom: 10px;
}
.listdemoListControls md-list-item > p, .listdemoListControls md-list-item > .md-list-item-inner > p, .listdemoListControls md-list-item .md-list-item-inner > p, .listdemoListControls md-list-item .md-list-item-inner > .md-list-item-inner > p {
-webkit-user-select: none;
/* Chrome all / Safari all */
-moz-user-select: none;
/* Firefox all */
-ms-user-select: none;
/* IE 10+ */
user-select: none;
/* Likely future */
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.js"></script>
<script>
angular.module('MyForm', ['ngMaterial'])
.config(function($mdIconProvider) {
$mdIconProvider
.iconSet('social', 'img/icons/sets/social-icons.svg', 24)
.iconSet('device', 'img/icons/sets/device-icons.svg', 24)
.iconSet('communication', 'img/icons/sets/communication-icons.svg', 24)
.defaultIconSet('img/icons/sets/core-icons.svg', 24);
})
.controller('ListCtrl', function($scope, $mdDialog) {
$scope.liststudent= [
{ name: 'Kevin', isgirl: false },
{ name: 'Sara', isgirl: true},
{ name: 'Bob', isgirl: false },
{ name: 'Laura', isgirl: true },
{ name: 'Peter', isgirl: false }
];
});
</script>
</head>
<body ng-app="MyForm">
<md-list ng-cloak="" ng-controller="ListCtrl">
<md-subheader class="md-no-sticky">Student list</md-subheader>
<md-list-item ng-repeat="topping in liststudent">
{{ topping.name }} <br />
<md-checkbox class="md-secondary" ng-model="topping.isgirl"></md-checkbox>
</md-list-item>
<md-divider></md-divider>
<md-list>
</md-list>
</md-list>
</body>
</html>
Screenshot Running on Mobile: 在移动设备上运行的屏幕截图:
It may be a network-related issue. 这可能是与网络有关的问题。 Have you tried copying the libraries locally?
您是否尝试过在本地复制库?
PS. PS。 I don't have enough reputation to comment yet, so I posted this as an answer.
我的信誉不足,因此无法发表评论,因此我将其发布为答案。 haha
哈哈
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.