2

In HTML I have a button and I am using ng-click event on it, like this:

ng-click="!user.name : openModel('lg') ? ''"

I am saying if user.name is not defined then call the function called openModel() else do nothing.

But it is generating the error

Error: $parse:syntax
Syntax Error

Syntax Error: Token ':' is an unexpected token at column 33 of the expression [!user.name :] starting at [{4}].

So what is wrong here?

Thanks.

2 Answers 2

3

The correct syntax would be ng-click="!user.name ? openModel('lg') : angular.noop()". angular.noop() is a function that peforms no operations.

Sign up to request clarification or add additional context in comments.

Comments

3

Don't put any Condition Expression in Template. Do it in the controller code,

ng-click="openModel('lg')"

Controller:

$scope.openModel = function(value) {
    if ($scope.name) {
       Open();
    }
}

Comments

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.