请在 Plunker 现场试用 - http://plnkr.co/edit/js7WOhjgKwUeElrdNwv0?p=preview
请问我该如何解决这个问题?与 Plunker 和下面的示例不同,我正在处理的指令需要一个隔离的范围(或者至少当前的实现使用一个,我宁愿不重写它)。
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script data-require="angular.js@*" data-semver="1.1.5" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
<script>
var app = angular.module("MyApp",[]);
app.directive("myDirective", function(){
return {
//scope:{},
link: function(){}
};
});
</script>
<style>
.ng-invalid{
border: 1px solid red;
}
</style>
</head>
<body ng-app="MyApp">
<h1>My Directive</h1>
<p>Test the checkbox below then uncomment //scope:{} and try again.</p>
<input type="checkbox" ng-model="isActive" />
<input type="text" ng-model="foo"
my-directive
ng-disabled="!isActive"
ng-required="isActive" />
</body>
</html>
最好的问候,汉斯