0

I am coding a CRUD application in Angular and Web API. In the create/edit form (same template), I need to display an error message if 2 input fields don't have the same number of comma ','.

I found a way to make it work but I don't like it, I think it needs to be "angularized" but I don't know how.

Controller:

$scope.isColumnCountOk = true;
$scope.checkColumnCountOk = function () { $scope.isColumnCountOk = AdminUtils.isColumnCountOk($scope.item.columnSqlNames, $scope.item.columnTitles) };

Template:

 <input type="text" class="form-control" ng-model="item.columnTitles" placeholder="Report Column 1,Report Column 2,Report Column 3,..." ng-blur="checkColumnCountOk()" required />
            <div ng-hide="isColumnCountOk">
                <br />
                <div class="alert alert-danger" ><strong>Warning. </strong>Mismatch between column numbers</div>
            </div>

I would like to get rid of the $scope.isColumnCountOk and have the function called directly from the template, without storing the return value in the scope.

Any advice?

Bruno

1 Answer 1

1

I think both of these ways should work...

$scope.isColumnCountOk = function () { 
    return AdminUtils.isColumnCountOk($scope.item.columnSqlNames, $scope.item.columnTitles);
};

<div ng-hide="isColumnCountOk()">
    ...
</div>

Or

$scope.isColumnCountOk = AdminUtils.isColumnCountOk; 

<div ng-hide="isColumnCountOk(item.columnSqlNames, item.columnTitles)">
    ...
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

And I can get rid of ng-blur, that's perfect!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.