正在处理一个简单的联系表单,如果 $scope 未定义,我需要显示一条错误消息。
验证部分可以工作,但是我不记得如何在 html 端的 ng-show 下启用消息 View 。
HTML:
<p class="response error" ng-show="error">{{errorMessage}}</p>
JS:
var $emptyContent = 'Please enter your prices.';
app.controller('priceForm', ['$scope', '$http', function($scope, $http){
$scope.formData;
// Process the form data
$scope.submitForm = function () {
console.log($scope.formData);
if($scope.formData == null) {
// Show empty content message
console.log($emptyContent);
}
}
}])
最佳答案
只需在 Controller 内将 error
标志设置为 true
或者,您可以只使用 ng-show="errorMessage"
正如 @ryanyuyu 在评论中建议的那样。
代码
$scope.submitForm = function () {
console.log($scope.formData);
if($scope.formData == null) {
$scope.error = true; //or //$scope.errorMessage = $emptyContent;
}
};
关于javascript - Angular ng-显示如何使其可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34578150/