我试图从 Javascript 代码中设置一个 angularjs 模型值,但它不起作用。我总是得到该属性的空值。下面是我的html代码片段:
<script type="text/javascript">
VSS.init({
explicitNotifyLoaded: true,
usePlatformScripts: true,
usePlatformStyles: true
});
VSS.ready(function () {
console.log("Organization name " + VSS.getWebContext().account.name);
var scope = angular.element(document.querySelector('#hubContainer')).scope();
scope.$apply(function () {
scope.DashboardModel.AccountKey = VSS.getWebContext().account.name;
})
});
</script>
<div class="ng-cloak tree-master-wrapper">
<div id="hubContainer" class="ng-scope" data-ng-controller="MyController">
Some code comes here…….
</div>
但由于某些原因,console.log(“AccountKey” + $scope.DashboardModel.AccountKey) 是空的。任何想法?我使用https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js