javascript - varible not defined in AngularJS -
i have started play around bit angularjs, , got myself problem. error i'm told app not defined
on line 5 in services.js. looked around bit , learned app has defined outside of function or it's not public, moved out, didn't help, tried move script-tags in index.html header instead of after html. here code have.
index.html
<!doctype html> <html data-ng-app="restclientmodule"> <head> <title></title> </head> <body> <div ng-controller="angularjs_wcfcontroller"> {{returnresult}} </div> </body> </html> <script src="../scripts/angular.js"></script> <script src="../scripts/test/services.js"></script> <script src="../scripts/test/modules.js"></script> <script src="../scripts/test/controller.js"></script>
modules.js
/// <reference path="../angular.js" /> /// <reference path="../angular.min.js" /> var app; (function () { app = angular.module("restclientmodule", []); })();
services.js
/// <reference path="../angular.js" /> /// <reference path="../angular.min.js" /> /// <reference path="modules.js" /> app.service("angularjs_wcfservice", function ($http) { this.getdata = function () { return $http.get("http://localhost:61794/service1.svc/getdata"); }; });
controllers.js
/// <reference path="../angular.js" /> /// <reference path="../angular.min.js" /> /// <reference path="modules.js" /> /// <reference path="services.js" /> app.controller("angularjs_wcfcontroller", function ($scope, $rootscope, $window, angularjs_wcfservice) { $scope.returnresult = "none"; function getdata() { var promiseget = angularjs_wcfservice.getdata(); promiseget.then(function (pl) { $scope.returnresult = pl.data }, function (errorpl) { }); } });
as seen have include "services.js"(app not define here )
before "modules.js"(app define here )
in define app. should include "modules.js"
before "service.js"
fix problem
so should :
<script src="../scripts/angular.js"></script> <script src="../scripts/test/modules.js"></script> <script src="../scripts/test/services.js"></script> <script src="../scripts/test/controller.js"></script>
Comments
Post a Comment