Answer the question
In order to leave comments, you need to log in
How does a factory work?
https://www.youtube.com/watch?v=2tx1B8zXNqo&list=P...
This tutorial says that
<!DOCTYPE html>
<html ng-app='app' lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.4/angular.min.js"></script>
<script src="script.js"></script>
<div ng-controller='myCtrl'>
items: <input ng-model='i' min="0" step="1" type="number"><br>
count: <input ng-model='c' min="0" step="1" type="number"><br>
price: {{i * c}} {{hello}}
</div>
</body>
</html>
var ang = angular.module('app', []);
ang.controller('myCtrl', function($scope, myFactory) {
$scope.myFactory = myFactory;
$scope.i = 1;
$scope.c = 20 ;
});
ang.factory('myFactory', function() {
return {
hello: '$'
};
});
Answer the question
In order to leave comments, you need to log in
You refer to the {{hello}} variable in the template, but your factory is stored in myFactory. Should be {{myFactory.hello}}.
How factories work - a lot of material on the net. If you need to learn, better switch to the new version of Angular.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question