无法从Javascript设置角度模型

问题描述 投票:0回答:1

我试图从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

angularjs angularjs-scope vssdk
1个回答
0
投票

我能够通过将此条目添加到“MyController”来解决此问题:

MyModule.controller('MyController', ['$scope', function($scope){

    $scope.DashboardModel = new DashboardModel(); 

    var checkPermission = function (selectedTeam) {
    VSS.require(["VSS/Service", "VSS/Security/RestClient"], 
    function(VSS_Service, Security_RestClient) {   
       $scope.DashboardModel.AccountKey = VSS.getWebContext().account.name;
    });
   });
  }
© www.soinside.com 2019 - 2024. All rights reserved.