如果使用属性给出值,则ng-hide不会在指令中工作

时间:2015-08-02 17:22:36

标签: angularjs angularjs-directive

我的指令模板中有一个视频元素,我希望在给予视频流并且shared-vid设置为true时显示它。这是指令的使用方式:

<video-player vid-src="{{getLocalVideo()}}" aud-src="{{getLocalAudio()}}" user-name=:"{{getUsername()}}" shared-vid="{{isLocalVideoShared()}}"></video-player>

假设isLocalVideoShared()现在正在返回真值。

以下是我的指令模板:

<div class="videoBoxContainer">
  <div class="hideVideoBox" ng-hide="{{hasSharedVideo()}}"></div>
  <video ng-src="{{trustSrc()}}" autoplay width="170px" ng-show="{{hasSharedVideo()}}" class="videoelement"></video>
  <span>{{peerUserName()}}</span>
  <audio autoplay ng-src="{{trustAudSrc()}}"></audio>
</div>

这是我的指令的编码方式:

.directive('videoPlayer', function ($sce) {
 return {
  template: 'directives/templates/videoplayer.html',
  restrict: 'E',
  replace: true,
  scope: {
    vidSrc: '@',
    audSrc: '@',
    userName: '@',
    sharedVid: '@'
  },
  link: function (scope) {
    scope.trustSrc = function () {
      if (!scope.vidSrc) {
        return undefined;
      }
      return $sce.trustAsResourceUrl(scope.vidSrc);
    };
    scope.hasSharedVideo = function () {
      return scope.sharedVid;
    };
    scope.trustAudSrc = function () {
      if (!scope.audSrc) {
        return undefined;
      }
      return $sce.trustAsResourceUrl(scope.audSrc);
    };
    scope.peerUserName = function () {
      if (!scope.userName) {
        return undefined;
      }
      return scope.userName;//$sce.trustAsResourceUrl(scope.userName);
    };
  }
 };
});

在给予shar​​ed-vid属性的真实值时,它仍然没有显示视频元素。

为什么它没有得到我使用属性发送的值,它得到其他值,如vid-src。

0 个答案:

没有答案