I have the following code...
var app = angular.module('plunker', []);
TestController = function ($scope, $interval) {
$scope.test = this;
$scope.name = 'World';
this.init();
$interval(function () {
//Added this because we shouldn't update until we either get the user data or that request fails
$scope.test.init();
}, 500);
};
TestController.prototype.init = function () {
console.log("Test this thing");
};
app.controller('MainCtrl', TestController);
This works great but now I need to include the init function in another controller so I want both to inherit from a common prototype. However, when I try this plunker it doesn't seem to work.
What is the proper way to handle this sort of thing in JS?
function TimeBoxbut in prototype try assignTestController.prototype = new Test()app.jsfile, or add reference totest.jsinindex.htmltest.jsin pageindex.html- you need add reference to this script file like<script src="test.js"></script>:-)test.jsbeforeapp.js;)