无法在angularjs中传递指令内的对象?

时间:2017-03-03 14:55:55

标签: javascript angularjs restangular

这是指令

的代码
module.exports = ()=>{
  return {
    restrict: 'E',
    templateUrl: "/components/editor/editor.html",
    scope: {channel: '='},
    controller: "editorCtrl"
  };
};

控制器

module.exports = ($scope,$rootScope)=>{
  console.log($scope.channel);
};

我正在使用

从模板中调用相同内容
.container(ng-controller="blogCtrl" ng-init="getOne()")
  h1(ng-bind="blog.title")
  editor(channel="blog")

blogCtrl的相关部分

module.exports = ($scope,$rootScope,api,$routeParams)=>{
  $scope.getOne = ()=>{
    $scope.data = null;
    $scope.error = null;
    var id = $routeParams.blogSlug;
    api.one("blog",id)
      .then((resp)=>{
        $scope.blog = resp.data;
      })
      .catch((err)=>{
        $scope.error = err.message;
      });
  }
};

api工厂的代码是

module.exports = ($rootScope,$localStorage,Restangular)=>{
  var helper = {};

  helper.one = (model,id)=>{
    return new Promise((fullfill,reject)=>{
      $rootScope.$broadcast("loaderInit");
      Restangular
        .one(model,id)
        .get()
        .then(fullfill)
        .then(()=>{
          $rootScope.$broadcast("loaderEnd");
        })
        .catch((err)=>{
          $rootScope.$broadcast("loaderEnd");
          reject(err);
        });
    });
  }
  return helper;
}

我不确定为什么但是频道总是未定义的。我哪里错了?

0 个答案:

没有答案