1

I am new to angularjs.I started an angular application with the help of yeoman generator. I was able to run the app in localhost but not able to run without any server.My application doesnt required any server.Please see my code below.

<script src="bower_components/jquery/dist/jquery.js"></script>
            <script src="bower_components/angular/angular.js"></script>
            <!-- <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> -->
            <script src="bower_components/angular-animate/angular-animate.js"></script>
            <script src="bower_components/angular-cookies/angular-cookies.js"></script>
            <script src="bower_components/angular-resource/angular-resource.js"></script>
            <script src="bower_components/angular-route/angular-route.js"></script>
            <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
            <script src="bower_components/angular-touch/angular-touch.js"></script>
            <script src="bower_components/angular-aria/angular-aria.js"></script>
            <script src="bower_components/angular-material/angular-material.js"></script>
            <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
            <script type="text/javascript" src="scripts/app.module.js"></script>
            <script type="text/javascript" src="scripts/controllers/wizard.js"></script>

        </head>
        <body ng-app="myApp">
            <div ui-view></div>
        </body>

Below is the main app module:

angular
  .module('myApp', [
    'ngSanitize',
    'ngCookies',
    'ngResource',
    'ui.router',
    'ngMaterial'
  ])
  .run(function () {
      alert("Run Block");

  })
.config(function ($urlRouterProvider,$stateProvider) {
  $urlRouterProvider.otherwise('/wizard');
    $stateProvider
    .state('wizard', {
      url: '/wizard',
      templateUrl: 'views/wizard.html',
      controller: 'WizardController',
      controllerAs: 'vm'
    })
    .state('wizard.layer', {
      url: '/layer',
      templateUrl: 'views/layer.html',
      controller: 'LayerController',
      controllerAs: 'vm'
    });
  });

In my views folder above mentioned two html files are there. But i am not able to run files without server.Its working with grunt serve. Even my run block in angularjs not get fired when i openeed index.html in firefox. I dont know why it is happening.Can anyone help me out of this problem. Any help will be appreciated.

Thanks.

3
  • Open your web page in FF and press F12 to bring up the developer tools. There you can see failed http requests 8missing files) and java script errors. Commented Dec 4, 2015 at 16:49
  • 2
    You need a server. Angular uses ajax to pull in and parse template files. Even for static files, you need something serving them. This is a browser security issue. Commented Dec 4, 2015 at 16:50
  • But i want to know is there any way exists to run html file without a server as i need to build an phonegap application.Phonegap applications are served without server in mobiles.I saw an ionic angular application running without a localhost.I have no errors in the console of firefox. Commented Dec 5, 2015 at 2:18

1 Answer 1

1

You are using urlRouterProvider which makes ajax requests to render the html files. These requests will fail because there is no server running to serve the request.

Sign up to request clarification or add additional context in comments.

2 Comments

But ionic application using angularjs working without localhost in firefox. Is there a way to run angularjs without server as i want to build a phonegap application where server support may not be there?
Look there is difference between a web-app built using angularjs and a mobile application built using the angularjs framework. Read some tutorials on using Ionic or phonegap, they launch the app in web-browser for testing and debugging but still there is mechanism to handle the app requests, they are not simply running, complete environment is setup for them to run. Just google and you will find tons of tutorials out there. I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.