1

I am new to AngularJS and do have the task of enhancing existing code.

Simplified, the following is in the html-file:

<div class="popup-list" ng-controller="NumberCtrl">
  First number: <input type="number" ng-init="$scope.firstNum">
</div>

And this I want to have referred in a JavaScript-file:

angular.module('app').controller('NumberCtrl', function ($scope)
{
  $scope.firstNum = 100
});

However the modal window popups up providing the input field, but no value = 100 is pre-defined.

What is going wrong here?

1
  • you should use ng-model instead of ng-init which provides you two way binding feature.. Commented Jan 17, 2016 at 9:00

2 Answers 2

1

you don't need to tag scope in view .

whatever you use on view it'll get from $scope.

use ng-model in input control in order to bind data.

Like this

First number: <input type="number" ng-model="firstNum">

You are may be getting module without setting it.

Try like this

angular.module('app',[]).controller

To get a module

angular.module('app')

To set a module

angular.module('app',[])
Sign up to request clarification or add additional context in comments.

Comments

0

Also, you have to initialize the module like: angular.module('app', []);. Before using it (note the empty array [] that tells angular that you have 0 dependencies and you are initializing a new module).

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.