与模板中的 ngModel 共享作用域指令
Shared scope directives with a ngModel in the template
有类似的东西:
module.directive('myCustomInput', function($compile) {
return {
restrict: 'E',
template: '<input ng-model="$scope.myVar"></input>'
}
}
这不绑定到模型,我可以让它工作的唯一方法是在范围内指定一个变量:{},然后使用它,这实际上是我不想要的。
有什么解决办法吗?
您无需在视图
中提及 $scope
这样试试
<input ng-model="myVar"></input>
有类似的东西:
module.directive('myCustomInput', function($compile) {
return {
restrict: 'E',
template: '<input ng-model="$scope.myVar"></input>'
}
}
这不绑定到模型,我可以让它工作的唯一方法是在范围内指定一个变量:{},然后使用它,这实际上是我不想要的。
有什么解决办法吗?
您无需在视图
中提及$scope
这样试试
<input ng-model="myVar"></input>