javascript - Angular.js Yeoman app.js file not running custom function -
I have an angular .js installation from a male generator for Express.js, I was under the impression that when the node .js server (with grunting service) starts, if ap js file is used to run the function i. However, my function left in my app / script / app.js.Run API () ; Is not running. Why is it like this? I app. How can I run a function in JS? There is no error on the output when the server starts:
a @demo ~ / node_stoff $ cat app / script / app.js
'strict use'; Var rest = Requirement ('. / Memory.js'); Rest.runApi (); Var myappApp = angular The module ('myappApp', ['ngCookies', 'duScroll', 'ngRoute']) config (function ($ route provider) {$ routeProvider.when ('/ home', {templateUrl: 'views / $ RouteProvider.when (' / First ', {templateUrl:' views / first.html ', controller:' first controller '}); $ routeProvider.otherwise ({redirectTo: / home.html', controller: 'home controller'}) '/ home'} );}); MyappApp.controller ('Scroller', function ($ radius, $ location, $ document, $ anchor scall) {$ scope.scrollTo = function (id) {var el = angular.element (document.getElementById (id)); $ Document .scrollTo (L, 2000);}}); MyappApp.controller ('Home Controller', Function ($ Scope, $ location, $ Anchor Scall) {$ scope.scrollTo = Function (id) {$ location.hash (ID); $ Anchor Scarl ();}}); MyappApp.controller ('FirstController', function ($ radius, $ location, $ anchor scall) {$ scope.scrollTo = function (id) {$ location.hash (id); $ anchor skarl ();}}); A @ demo ~ / node_stoff $ cat app / script / memory.js
var rest = need ('restler'); Check = 'chMNWXNki7'; Url = 'https: //monitoring.api.rackspacecloud.com/v1.0/1324/'; Slug = 'entities / enij5mKIvs / checks'; Mode = '/ test'; URL = check + url + slog + check + mode header = {header: {"x-as-token": "377c"}} function run API () {rest.post (url, header) .on ('complete 'Function (data, feedback) {console.log (JSON.stringify (data, "\ n", 2)); console.log ("------------------ - ------------------------------------- "); console.log (response.statusCode); }); } Module.exports.runApi = runApi; One @ demo ~ / node_stoff $ A @ demo ~ / node_stoff $ clutter service
Running "service" function is running "Clear: Cleaning server "(clean) function .mpg ... running fine" bowerInstall: app "(bowerInstall) is running" concurrent: server "(concurrent) work is going on" copy: styles "(copy) function running 1 files being copied, without errors, execution time (2014-04-22 01:20:32 UTC) loading work 4ms à ¢  ¢  ¢  ¢ ¢ A 27% copy: Can be used in the genre â € ¢ â € ¢ Scandal: â € ¢ Created "autoprefixer: dist" (autoprefixer) function prefixed file ".tmp / styles / main.css", running a 67% ¢  ¢ â € ¢ ¢ 67% total 15ms. Connecting to "Connect: LiveLoad" (Connect) function is connected to the web server at 0.0.0.0:9000. Waiting for the "Clock" function is running ...
When the angular application If bootstrap, it is only running the code within its framework, in order to load it / run it at the beginning of the bootstrap process, you can put it within the run method of the application.
myappApp.run (function apprun () {var rest = requirement ('. / Memory.js'); rest.runApi ();}); The other place that you can potentially do is within a factory. As there is a solo song in the angular of factories, it will also be run during bootstrap. The difference is that the order of factory initialization is uncertain, but if you want to use the performance result later, it would be good.
myApp.factory ('RestRunFactory', function factoryrun () {var rest = required ('. / Memory.js'); rest.runApi ();});
Comments
Post a Comment