2014-10-06 60 views
1

我正在使用Typeahead directive from the UI Bootstrap framework。我在另一個指令中使用這個指令。我的外部指令的定義是這樣的:在子指令中獲取範圍值

.directive('myDirective', function() { 
    return { 
    restrict:'E', 
    transclude: true, 
    scope: { 
     showLinks: '=?', 
     query: '=' 
    }, 
    templateUrl: '/directives/my-directive.html', 
    controller: function ($scope) { 
     if (angular.isUndefined($scope.showLinks)) { 
     $scope.showLinks = true; 
     console.log('show links? ' + $scope.showLinks); 
     } 
    } 
    }; 
}); 

我-directive.html看起來是這樣的:

<div style="width:100%;"> 
    <span>{{showLinks}}</span> <!-- renders just fine --> 
    <input type="text" autofocus autocomplete="off" class="form-control" ng-model="query" 
      typeahead="option as option.Name for option in getLocation($viewValue)" 
      typeahead-min-length="3" typeahead-template-url="location.html" /> 
    <script type="text/ng-template" id="location.html"> 
     {{showLinks}} <!-- Never renders --> 
     <span bind-html-unsafe="match.label | typeaheadHighlight:query"></span> 
    </script> 
</div> 

我打電話給我的指示是這樣的:

<my-directive show-links="true" /> 

我需要使用我用於打字的模板中的showLinks的值。不過由於某種原因,它並沒有被傳入模板中。我相信這與範圍界定有關。如上所示,我通過將值綁定到UI來得出這個結論。 showLinks的值在我的模板中顯示得很好。但是,它不會出現在我的指令中的typeahead實例的模板中。

我在做什麼錯?我覺得我很親密。然而,我一直在努力。

感謝您提供任何幫助!

+0

你是什麼