这种情况仅发生在 iOS 版 Chrome 中。 我在 html 中有类似的东西。
<html ng-app="MY_APP">
<head ng-conroller="headCtrl as head">
<title ng-bind="head.title"></title>
... libraries...
<link rel="stylesheet" type="text/css" ng-href="./css/{{ head.style }}.css"/>
</head>
<body ng-controller="mainCrtl as main">
</body>
</html>
问题是 headCrtl 无法在 iOS 版 Chrome 中执行。
MY_APP.controller('headCtrl', ['$rootScope', '$scope', '$location', function ($rootScope, $scope, $location) {
var vm = this;
var host = $location.host();
if (host.indexOf('site1') > -1) {
vm.style = 'site1';
} else
if (host.indexOf('site2') > -1) {
vm.style = 'site2';
}
$rootScope.brandCode = vm.style;
vm.title = 'Straps';
}]);
感谢您的建议。
最佳答案
您的 View 文件中有拼写错误。应该是:
<head ng-controller="headCtrl as head">
不是
<head ng-conroller="headCtrl as head">
关于javascript - iOS Chrome 和 AngularJS 不执行 HEAD 中的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366865/