【发布时间】:2014-07-12 14:41:44
【问题描述】:
我有以下 HTML:
<ng-view>
<tabset>
<tab>
<tab-heading>
<i class="glyphicon glyphicon-info-sign"></i>
</tab-heading>
<div>
<div>
<div>{{selectedWord.translation}}</div>
</div>
...
</ng-view>
以及为视图加载的控制器:
angular.module('app').controller('SampleController', function ($scope) {
$scope.selectedWord = {translation: '[te]'};
}
ng-view 指令创建了一个新作用域,我认为它会作为参数注入到SampleController 构造函数中。
tabset 创建自己的隔离作用域,因此它不会从ng-view 创建的作用域继承属性。
.directive('tabset', function() {
return {
restrict: 'EA',
transclude: true,
replace: true,
scope: {
type: '@'
},
每个tab 指令还创建自己的范围,该范围也不是从tabset 指令创建的范围继承的。
.directive('tab', ['$parse', function($parse) {
return {
require: '^tabset',
restrict: 'EA',
replace: true,
templateUrl: 'template/tabs/tab.html',
transclude: true,
scope: {
active: '=?',
heading: '@',
onSelect: '&select', //This callback is called in contentHeadingTransclude
//once it inserts the tab's content into the dom
onDeselect: '&deselect'
},
我不明白的是为什么可以从tab 指令创建的范围内访问ng-view 指令创建的范围内定义的属性tab 指令(它本身是独立的范围和前面是 tabset) 创建的隔离范围?
【问题讨论】:
标签: angularjs