Javascript Angularjs ng单击清除输入并更新范围

Javascript Angularjs ng单击清除输入并更新范围,javascript,angularjs,scope,directive,Javascript,Angularjs,Scope,Directive,1。指令: app.directive('inputField', function() { return { restrict: 'E', require: 'ngModel', scope: { words: '=ngModel' }, transclude: true, template: "<input type='text' ng-model='wor

1。指令:

app.directive('inputField', function() {
    return {
        restrict: 'E',
        require: 'ngModel',
        scope: {
            words: '=ngModel'
        },
        transclude: true,

        template: "<input type='text' ng-model='words' placeholder='Translate' />"
    };
});
$scope.clear = function() {
    $scope.words = { word: '' };
};
<input-field id='inputWord' value='' name="data1" ng-model="words.word"></input-field>
3。视图如下所示:

app.directive('inputField', function() {
    return {
        restrict: 'E',
        require: 'ngModel',
        scope: {
            words: '=ngModel'
        },
        transclude: true,

        template: "<input type='text' ng-model='words' placeholder='Translate' />"
    };
});
$scope.clear = function() {
    $scope.words = { word: '' };
};
<input-field id='inputWord' value='' name="data1" ng-model="words.word"></input-field>

单击clear()后,{{words.word}}和输入中的值仍然存在,$scope被破坏

请告诉我如何清除所有输入
ng repeat
和更新范围?

像这样尝试

var-app=angular.module('app',[])
应用程序控制器('ctrl',函数($scope){
$scope.words=[{word:'input1'},{word:'input2'},{word:'input3'}];
$scope.clear=函数(){
$scope.words=[{word:'},{word:'},{word:'}];
};
});
app.directive('inputField',function(){
返回{
限制:'E',
要求:'ngModel',
范围:{
单词:'=ngModel'
},
是的,
模板:“”
};
});

清楚的
像这样试试

var-app=angular.module('app',[])
应用程序控制器('ctrl',函数($scope){
$scope.words=[{word:'input1'},{word:'input2'},{word:'input3'}];
$scope.clear=函数(){
$scope.words=[{word:'},{word:'},{word:'}];
};
});
app.directive('inputField',function(){
返回{
限制:'E',
要求:'ngModel',
范围:{
单词:'=ngModel'
},
是的,
模板:“”
};
});

清楚的

不幸的是,在clear()之后,$scope不起作用。我的意思是,当我输入一个输入时,它会输入所有的输入。因为所有输入的模型都是相同的。每个输入都应该有唯一的模型。谢谢,但这不是我想要的,如果我不知道我有多少输入呢?我的输入是通过ID计数从数据库生成的。很遗憾,在清除()之后,$scope不起作用。我的意思是,当我输入一个输入时,它会输入所有的输入。因为所有输入的模型都是相同的。每个输入都应该有唯一的模型。谢谢,但这不是我想要的,如果我不知道我有多少输入呢?我的输入通过ID计数从数据库生成。