W
W
whiteleaf2015-09-21 09:51:56
JavaScript
whiteleaf, 2015-09-21 09:51:56

What is the correct way to implement loop in javascript?

Hello!
Please tell me how you can run through the object using loop, get the necessary information and add data to another part of the code.

var App = angular.module('App', ['ngRoute']);

var partialDir = '/partials/';
var pageFormat = '.html';

var pages = {
    'home': {
        'url': '/',
        'partialName': 'index',
        'link': partialDir + this.partialName + pageFormat,
        'controllerName': this.partialName + 'Controller',
        'pageTitle': 'Welcome home'
    },
    'page': {
        'url': '/page',
        'partialName': 'page',
        'link': partialDir + this.partialName + pageFormat,
        'controllerName': this.partialName + 'Controller',
        'pageTitle': 'Page'
    },
    'page2': {
        'url': '/page2',
        'partialName': 'page2',
        'link': partialDir + this.partialName + pageFormat,
        'controllerName': this.partialName + 'Controller',
        'pageTitle': 'Page2'
    }
};

App.config(function($routeProvider,$locationProvider){
    $routeProvider
        .when('/',{
            templateUrl: '/partials/index.html'
        })
        .when('/page', {
            templateUrl: '/partials/page.html'
        })
        .when('/page2', {
            templateUrl: '/partials/page2.html'
        })
        .when('/admin', {
            templateUrl: '/partials/admin.html'
        })
        .otherwise({
            redirectTo: '/'
        });

    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-09-21
@whiteleaf

https://docs.angularjs.org/api/ng/function/angular...
https://developer.mozilla.org/en/docs/Web/JavaScri...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question