javascript2016 javascript2016 - 2 months ago 6
AngularJS Question

Angular - Why won't my ui-view show my template html text?

I wonder why my template which I refer to in my angular state ('home') won't be shown - in my index.html I included a tag. Anyone knows?Thank you!

app.js:

var app = angular.module('portfolio', ['ui.router']);


html:

<body ng-app="portfolio">
<p>hellooooo</p>
<ui-view></ui-view>

<script src="angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.0-beta.2/angular-ui-router.js"></script>
<script src="js/app.js"></script>
<script src="js/home/home.js"></script>
</body>


home.js:

app.config(function ($stateProvider) {
$stateProvider.state('home', {
url: '/',
templateUrl: '/browser/js/home/home.html'
});
});


home.html:

<div><p>not working</p></div>

Answer

I think your router are not able to match / url. That's why you have to specify a default state, because not always your url will come with /.

Consider forcing a default state like so:

$stateProvider.otherwise('/');