0

Hi I need to know how to initialize multiple application variables in angularjs..

Here what I have done..

<div ng-app="" ng-init="firstName='John'" ng-init="secName='Carter'">
    <div>
        Name is 
    <div ng-bind="firstName +' ' + secName"></div>
    </div>

</div>

But I can't get the correct output of "John Carter"

2 Answers 2

8

do it like this,

<div ng-app="" ng-init="firstName='John';secName='Carter'">
Sign up to request clarification or add additional context in comments.

Comments

1

You can call a scope function in ng-init

<div ng-app="MyApp" ng-init="initialise()">
    ...
</div>

In your corresponding controller, you can initialise all your scope variables.

$scope.initialise = function() {
   $scope.firstName = 'John';
   $scope.secName = 'Carter';
}

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.