Hello First of all I am a complete beginner at both javascript and angular. I have made the beginning of an app with everything working inside one single .js file. I found the angular styleguide (https://github.com/johnpapa/angular-styleguide) and thought i should adapt this way of working, mainly because I have otherwise no idea of what I am doing, but also to try to keep some kind of consistency troughout the app. And because I have no "own" style of doing things yet this could be a good start to get a nice structure.
I have now made 3 .js files and 1 html page. One "main module" which is then the "setter" and one factory for getting data form the backend and one controller. When i try to render i get following error: Error: [ng:areq] Argument 'TempController' is not a function, got undefined http://errors.angularjs.org/1.3.15/ng/areq?p0=TempController&p1=not%20a%20function%2C%20got%20undefined at REGEX_STRING_REGEXP (angular.js:63) at assertArg (angular.js:1587) at assertArgFn (angular.js:1597) at angular.js:8470 at angular.js:7638 at forEach (angular.js:331) at nodeLinkFn (angular.js:7625) at compositeLinkFn (angular.js:7117) at compositeLinkFn (angular.js:7120) at compositeLinkFn (angular.js:7120)angular.js:11655 (anonymous function)angular.js:8596 $getangular.js:14567 $get.Scope.$applyangular.js:1455 bootstrapApplyangular.js:4203 invokeangular.js:1453 doBootstrapangular.js:1473 bootstrapangular.js:1367 angularInitangular.js:26304 (anonymous function)jquery.js:3094 n.Callbacks.jjquery.js:3206 n.Callbacks.k.fireWithjquery.js:3412 n.extend.readyjquery.js:3428 I so something is obviously wrong with the controller and because of the very few lines of code it would be an easy fix, but I have tried almost everything now and still I can not get it to work. Any ideas? Have been sitting with this for a couple of hours now, googling, stack overflow searching etc etc without success *index.html:* <!doctype html> <html ng-app="app" ng-strict-di> <head> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"> </head> <body> <div class="panel panel-default" ng-controller="TempController as tempcontroller"> <div class="panel-heading">Temperature sensors</div> <table class="table table-striped"> <tr> <th>#id</th> <th>payload</th> <th>timestamp</th> </tr> <tr ng-repeat="message in tempcontroller.messages | orderBy:'_id'"> <td>{{message._id}}</td> <td>{{message.payload}}°C</td> <td>{{message.timestamp | date:'HH:mm'}}</td> </tr> </table> </div> <script src="bower_components/jquery/dist/jquery.min.js"></script> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <script src="bower_components/angular-websocket/angular-websocket.js"></script> <script src="app/app.js"></script> <script src="app/app.dataservice.js"></script> <script src="app/app.tempcontroller.js"></script> </body> </html> *app.js:* (function() { 'use strict'; angular .module('app', []) })(); *app.dataservice.js:* (function() { 'use strict'; angular .module('app') .factory('dataservice', dataservice); dataservice.$inject = ['$http', '$websocket']; function dataservice($http, $websocket) { var ws = $websocket('ws://192.168.1.111:1880/admin/ws/nodedash/'); var nodesArray=[]; var service = { getValues: getValues(), status: status, send: send }; activate(); return service; function activate() { ws.onMessage(function(event) { console.log('message: ', event); var res; try { res = JSON.parse(event.data); } catch (e) { console.log=("Could not parse data from Websocket as JSON"); } var timestampObj = new Date(res.timestamp.replace(/-/g,"/")); res.timestamp = timestampObj; var found = false; for (var i = 0; i < nodesArray.length; i++) { //function to avoid adding same payload to same node again if (nodesArray[i]._id === res._id) { nodesArray[i] = res; console.log("Updating value for _id: "+nodesArray[i]._id); found=true; } } if (found==false) { nodesArray.push(res); console.log("Found new node (_id: " + res._id + "), please configure node in setup"); } }); ws.onError(function(event) { console.log('connection Error', event); }); ws.onClose(function(event) { console.log('connection closed', event); }); ws.onOpen(function() { $http.get("http://localhost:1880/api/getnodes/") .success(function(response) { for (var i=0;i<response.length;i++){ nodesArray.push(response[i]); var timestampObj = new Date(nodesArray[i].timestamp.replace(/-/g,"/")); nodesArray[i].timestamp = timestampObj; } console.log(nodesArray); }); }); } function getValues() { return nodesArray; } function status() { return ws.readyState; } function send(message) { if (angular.isString(message)) { ws.send(message); } else if (angular.isObject(message)) { ws.send(JSON.stringify(message)); } } } })(); *app.tempcontroller:* (function() { 'use strict'; angular .module('app') .controller('TempController', TempController); TempController.$inject = ['dataservice']; function TempController(dataservice) { var vm = this; vm.messages = dataservice.getValues(); } }); -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
