Variable not rendering with ng-bind

I am working on a sample application from a book, AngularJS .

In the following code, {{funding.needed}} does not appear as 10 * startingEstimate . It is displayed literally, i.e. Does not appear as {{funding.needed}} on the page.

Why?

 <html ng-app> <body ng-controller="TextController"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"> </script> <form ng-controller="StartUpController"> Starting: <input ng-change="computeNeeded()" ng-model="funding.startingEstimate"> Recommendation: {{funding.needed}} </form> <script> function StartUpController($scope) { $scope.funding = { startingEstimate: 0}; $scope.computeNeeded = function() { $scope.needed = $scope.startingEstimate * 10; }; } </script> </body> </html> 
+4
source share
1 answer

You need to remove the TextController, as you have not defined, and block the loading of other things like errors. You will also need to normalize the use of the $ scope.funding object in some places where you are trying to use only members without a parent link. Below is the working version (see His work on the plunker at http://plnkr.co/edit/Jz95UlOakKLJIqHvkXlp?p=preview )

 <html ng-app> <body> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"> </script> <form ng-controller="StartUpController"> Starting: <input ng-change="computeNeeded()" ng-model="funding.startingEstimate"> Recommendation: {{funding.needed}} </form> <script> function StartUpController($scope) { $scope.funding = { startingEstimate: 0}; $scope.computeNeeded = function() { $scope.funding.needed = $scope.funding.startingEstimate * 10; }; } </script> </body> </html> 
+3
source

Source: https://habr.com/ru/post/1483503/


All Articles