0
我有一個指令的角度和一個形式綁定到範圍變量。代碼:指令範圍
<my-directive></my-directive>
<form>
<input ng-model="username" required>
</form>
指令:
.directive('myDirective', function(){
restrict : 'E',
controller: function($scope){
console.log($scope.username); // Displays user name, same scope!!!
},
link: function(scope, element, attrs){
// Other codes
},
templateUrl: "templates/my-template-url.html"
}
})
用戶名變量可以在我的指令的控制器內到達。這不是我爲什麼期望的,因爲我關閉了指令,他們不應該共享相同的範圍?
爲什麼這樣嗎?