Angular Material and md-nav-bar routing not working





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm working into AngularJS and have decided to use the AngularJS Material library to assist in my first application. So far I have some very basic code I copied from https://material.angularjs.org/latest/demo/navBar which I have modified to fit my own needs. I'm having some trouble wrapping my head around routing my code is below please help me some one else



.js



var routerApp = angular.module('routerApp', ['ui.router','ngMaterial', 'ngMessages']);

routerApp.config(function ($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider

.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller:'HomeController'
})

// nested list with custom controller
.state('home.page1', {
url: '/page1',
templateUrl: 'templates/page1.html',
controller: function ($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
})

// nested list with just some random string data
.state('home.page2', {
url: '/page2',
templateUrl: 'templates/page2.html',
//template: 'I could sure use a drink right now.',
controller: function ($scope) {
$scope.paragraphs = ['paragraph1', 'paragraph2', 'paragraph3'];
}
})

});


home.html



<div layout="column" ng-cloak>
<md-content class="md-padding">
<md-nav-bar md-no-ink-bar="disableInkBar"
md-selected-nav-item="currentNavItem"
nav-bar-aria-label="navigation links">
<md-nav-item md-nav-href=".page1" name="page1">
Page One
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2">
Page Two
</md-nav-item>
<md-nav-item md-nav-href=".page1" name="page1">
Page Three
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2" disabled>
Page Four
</md-nav-item>
</md-nav-bar>
<div ui-view></div>
</md-content>
</div>


HomeController:



routerApp.controller('HomeController', function ($scope, $location,$state) {
$scope.goto = function(page) {
$state.go(page);
};
});









share|improve this question

























  • do you see any error on console?

    – Sajeetharan
    Nov 25 '18 at 4:13











  • no i did not get any errors

    – Krish
    Nov 25 '18 at 4:29











  • Did i do correct way routing?

    – Krish
    Nov 25 '18 at 4:29











  • remove url in each state and see

    – Sajeetharan
    Nov 25 '18 at 4:30











  • page1 and page 2 are the child components of home page

    – Krish
    Nov 25 '18 at 4:31


















1















I'm working into AngularJS and have decided to use the AngularJS Material library to assist in my first application. So far I have some very basic code I copied from https://material.angularjs.org/latest/demo/navBar which I have modified to fit my own needs. I'm having some trouble wrapping my head around routing my code is below please help me some one else



.js



var routerApp = angular.module('routerApp', ['ui.router','ngMaterial', 'ngMessages']);

routerApp.config(function ($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider

.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller:'HomeController'
})

// nested list with custom controller
.state('home.page1', {
url: '/page1',
templateUrl: 'templates/page1.html',
controller: function ($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
})

// nested list with just some random string data
.state('home.page2', {
url: '/page2',
templateUrl: 'templates/page2.html',
//template: 'I could sure use a drink right now.',
controller: function ($scope) {
$scope.paragraphs = ['paragraph1', 'paragraph2', 'paragraph3'];
}
})

});


home.html



<div layout="column" ng-cloak>
<md-content class="md-padding">
<md-nav-bar md-no-ink-bar="disableInkBar"
md-selected-nav-item="currentNavItem"
nav-bar-aria-label="navigation links">
<md-nav-item md-nav-href=".page1" name="page1">
Page One
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2">
Page Two
</md-nav-item>
<md-nav-item md-nav-href=".page1" name="page1">
Page Three
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2" disabled>
Page Four
</md-nav-item>
</md-nav-bar>
<div ui-view></div>
</md-content>
</div>


HomeController:



routerApp.controller('HomeController', function ($scope, $location,$state) {
$scope.goto = function(page) {
$state.go(page);
};
});









share|improve this question

























  • do you see any error on console?

    – Sajeetharan
    Nov 25 '18 at 4:13











  • no i did not get any errors

    – Krish
    Nov 25 '18 at 4:29











  • Did i do correct way routing?

    – Krish
    Nov 25 '18 at 4:29











  • remove url in each state and see

    – Sajeetharan
    Nov 25 '18 at 4:30











  • page1 and page 2 are the child components of home page

    – Krish
    Nov 25 '18 at 4:31














1












1








1








I'm working into AngularJS and have decided to use the AngularJS Material library to assist in my first application. So far I have some very basic code I copied from https://material.angularjs.org/latest/demo/navBar which I have modified to fit my own needs. I'm having some trouble wrapping my head around routing my code is below please help me some one else



.js



var routerApp = angular.module('routerApp', ['ui.router','ngMaterial', 'ngMessages']);

routerApp.config(function ($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider

.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller:'HomeController'
})

// nested list with custom controller
.state('home.page1', {
url: '/page1',
templateUrl: 'templates/page1.html',
controller: function ($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
})

// nested list with just some random string data
.state('home.page2', {
url: '/page2',
templateUrl: 'templates/page2.html',
//template: 'I could sure use a drink right now.',
controller: function ($scope) {
$scope.paragraphs = ['paragraph1', 'paragraph2', 'paragraph3'];
}
})

});


home.html



<div layout="column" ng-cloak>
<md-content class="md-padding">
<md-nav-bar md-no-ink-bar="disableInkBar"
md-selected-nav-item="currentNavItem"
nav-bar-aria-label="navigation links">
<md-nav-item md-nav-href=".page1" name="page1">
Page One
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2">
Page Two
</md-nav-item>
<md-nav-item md-nav-href=".page1" name="page1">
Page Three
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2" disabled>
Page Four
</md-nav-item>
</md-nav-bar>
<div ui-view></div>
</md-content>
</div>


HomeController:



routerApp.controller('HomeController', function ($scope, $location,$state) {
$scope.goto = function(page) {
$state.go(page);
};
});









share|improve this question
















I'm working into AngularJS and have decided to use the AngularJS Material library to assist in my first application. So far I have some very basic code I copied from https://material.angularjs.org/latest/demo/navBar which I have modified to fit my own needs. I'm having some trouble wrapping my head around routing my code is below please help me some one else



.js



var routerApp = angular.module('routerApp', ['ui.router','ngMaterial', 'ngMessages']);

routerApp.config(function ($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider

.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller:'HomeController'
})

// nested list with custom controller
.state('home.page1', {
url: '/page1',
templateUrl: 'templates/page1.html',
controller: function ($scope) {
$scope.dogs = ['Bernese', 'Husky', 'Goldendoodle'];
}
})

// nested list with just some random string data
.state('home.page2', {
url: '/page2',
templateUrl: 'templates/page2.html',
//template: 'I could sure use a drink right now.',
controller: function ($scope) {
$scope.paragraphs = ['paragraph1', 'paragraph2', 'paragraph3'];
}
})

});


home.html



<div layout="column" ng-cloak>
<md-content class="md-padding">
<md-nav-bar md-no-ink-bar="disableInkBar"
md-selected-nav-item="currentNavItem"
nav-bar-aria-label="navigation links">
<md-nav-item md-nav-href=".page1" name="page1">
Page One
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2">
Page Two
</md-nav-item>
<md-nav-item md-nav-href=".page1" name="page1">
Page Three
</md-nav-item>
<md-nav-item md-nav-href=".page2" name="page2" disabled>
Page Four
</md-nav-item>
</md-nav-bar>
<div ui-view></div>
</md-content>
</div>


HomeController:



routerApp.controller('HomeController', function ($scope, $location,$state) {
$scope.goto = function(page) {
$state.go(page);
};
});






angularjs angularjs-material






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 5:11









georgeawg

35.1k115470




35.1k115470










asked Nov 25 '18 at 3:34









KrishKrish

1,30162458




1,30162458













  • do you see any error on console?

    – Sajeetharan
    Nov 25 '18 at 4:13











  • no i did not get any errors

    – Krish
    Nov 25 '18 at 4:29











  • Did i do correct way routing?

    – Krish
    Nov 25 '18 at 4:29











  • remove url in each state and see

    – Sajeetharan
    Nov 25 '18 at 4:30











  • page1 and page 2 are the child components of home page

    – Krish
    Nov 25 '18 at 4:31



















  • do you see any error on console?

    – Sajeetharan
    Nov 25 '18 at 4:13











  • no i did not get any errors

    – Krish
    Nov 25 '18 at 4:29











  • Did i do correct way routing?

    – Krish
    Nov 25 '18 at 4:29











  • remove url in each state and see

    – Sajeetharan
    Nov 25 '18 at 4:30











  • page1 and page 2 are the child components of home page

    – Krish
    Nov 25 '18 at 4:31

















do you see any error on console?

– Sajeetharan
Nov 25 '18 at 4:13





do you see any error on console?

– Sajeetharan
Nov 25 '18 at 4:13













no i did not get any errors

– Krish
Nov 25 '18 at 4:29





no i did not get any errors

– Krish
Nov 25 '18 at 4:29













Did i do correct way routing?

– Krish
Nov 25 '18 at 4:29





Did i do correct way routing?

– Krish
Nov 25 '18 at 4:29













remove url in each state and see

– Sajeetharan
Nov 25 '18 at 4:30





remove url in each state and see

– Sajeetharan
Nov 25 '18 at 4:30













page1 and page 2 are the child components of home page

– Krish
Nov 25 '18 at 4:31





page1 and page 2 are the child components of home page

– Krish
Nov 25 '18 at 4:31












1 Answer
1






active

oldest

votes


















2














You might try with md-nav-sref




md-nav-sref is used as Ui-router state to transition to when this link
is clicked




<md-nav-item md-nav-sref="#!/page1" name="page1">
Page One
</md-nav-item>





share|improve this answer
























  • yes its working fine now

    – Krish
    Nov 25 '18 at 6:25












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464422%2fangular-material-and-md-nav-bar-routing-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You might try with md-nav-sref




md-nav-sref is used as Ui-router state to transition to when this link
is clicked




<md-nav-item md-nav-sref="#!/page1" name="page1">
Page One
</md-nav-item>





share|improve this answer
























  • yes its working fine now

    – Krish
    Nov 25 '18 at 6:25
















2














You might try with md-nav-sref




md-nav-sref is used as Ui-router state to transition to when this link
is clicked




<md-nav-item md-nav-sref="#!/page1" name="page1">
Page One
</md-nav-item>





share|improve this answer
























  • yes its working fine now

    – Krish
    Nov 25 '18 at 6:25














2












2








2







You might try with md-nav-sref




md-nav-sref is used as Ui-router state to transition to when this link
is clicked




<md-nav-item md-nav-sref="#!/page1" name="page1">
Page One
</md-nav-item>





share|improve this answer













You might try with md-nav-sref




md-nav-sref is used as Ui-router state to transition to when this link
is clicked




<md-nav-item md-nav-sref="#!/page1" name="page1">
Page One
</md-nav-item>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 6:24









SajeetharanSajeetharan

128k31186247




128k31186247













  • yes its working fine now

    – Krish
    Nov 25 '18 at 6:25



















  • yes its working fine now

    – Krish
    Nov 25 '18 at 6:25

















yes its working fine now

– Krish
Nov 25 '18 at 6:25





yes its working fine now

– Krish
Nov 25 '18 at 6:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53464422%2fangular-material-and-md-nav-bar-routing-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini