繁体   English   中英

为什么以下范围变量在我的指令中变得未定义?

[英]Why isn't the following scope variable becoming undefined inside my directive?

我试图获取panodatas的值(在我的控制器中定义为$scope.panodatas ),并在我的指令的link部分中使用它:

JS:

scope: {
        floorplan: "@",
        points: "=",
        panodatas: "=",
        getPanos: "&"
      },
      link: function(scope, element, attrs) {
        console.log(scope.panodatas)
        scope.getPanos().then(function() {
          console.log(scope.panodatas)

HTML:

  <pre>{{panodatas | json}}</pre>
  <panodata-editor
    floorplan="http://ac-x69r2ohx.clouddn.com/3171600a0de6f740c152.jpg"
    points="points"
    panodatas="panodatas"
    get-panos="getPanos()"
  >
  </panodata-editor>

但这不起作用,两个console.log(scope.panodatas)返回undefined 为什么是这样? 如何获取$scope.panodatas的值并将其用于link: function() {...}

注意:

<pre>{{panodatas | json}}</pre> <pre>{{panodatas | json}}</pre>正在工作,因此panodatas确实具有以下值:

[
  {
    "objectId": "56a74de0d342d30054170231",
    "index": 2,
    "x": 200,
    "y": 200,
    "createdAt": "2016-01-26T10:43:44.482Z"
  },
  {
    ...
  },
  ...

编辑:

这是在我的控制器中定义panodatas方式:

var all = function() { return $q.all([serviceUpload.getAllBuilding(isUpdated)]) }

$scope.getPanos = function() {
  return all().then(function(value) {
    $scope.buildingTree = JSON.parse(value)
    $scope.panoId = $routeParams.panoId
    $scope.pano = _($scope.buildingTree).chain().
    pluck('pano').
      flatten().
      findWhere({objectId: $scope.panoId}).
      value()
    $scope.panodatas = $scope.pano.panoData
  }, function(reason) {
    $scope.result = reason
  })
}

因为运行链接程序时,promise会返回panodatas。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM