为什么单击该按钮会将两个空字符串添加到html页面而不是相应的引用?
服务:
quotes.addData = function(quote){
quotesArr.push(quote);
}
控制器:
$scope.quoteToAdd = {
author : $scope.quoteAuthor,
text: $scope.quoteText
};
$scope.addQuote = quoteService.addData;
}
HTML:
Author :<input type="text" ng-show="showAdd" ng-model='quoteAuthor' name="name" value="">
Quote:<input type="text" ng-show="showAdd" ng-model='quoteText' name="name" value="">
<button ng-click='addQuote(quoteToAdd)' ng-show="showAdd" type="button" name="button">Submit</button>
答案 0 :(得分:2)
您的表单中有错误的ng-model绑定:
binomialDistribution.java:37: error: illegal start of type
return total;
自从控制器对象初始化范围属性的值以来最初不是通过引用而自上面的代码。下面列出的新控制器应该适用于您想要的工作。
控制器(新):
Author :<input type="text" ng-show="showAdd" ng-model='quoteToAdd.author' name="name" value="">
Quote:<input type="text" ng-show="showAdd" ng-model='quoteToAdd.text' name="name" value="">
<button ng-click='addQuote(quoteToAdd)' ng-show="showAdd" type="button" name="button">Submit</button>
控制器(旧):
$scope.quoteToAdd = {
author : null,
text: null
};
$scope.addQuote = quoteService.addData;
}