【问题标题】:Unable to Set Angular Model from Javascript无法从 Javascript 设置 Angular 模型
【发布时间】:2019-08-26 21:13:56
【问题描述】:

我试图从 Javascript 代码中设置一个 angularjs 模型值,但它不起作用。我总是得到该属性的空值。以下是我的 html 代码的 sn-p:

  <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】:

    我能够通过将此条目添加到“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;
        });
       });
      }
    

    【讨论】:

      猜你喜欢
      • 2013-12-20
      • 1970-01-01
      • 2014-10-09
      • 2014-02-21
      • 1970-01-01
      • 2014-05-29
      • 2020-07-27
      • 1970-01-01
      • 2014-10-30
      相关资源
      最近更新 更多