[英]Angular Routing with UI-route issue
Im new at Angular and I've been following this tutorial . 我是Angular的新手,我一直在关注本教程 。 Everything was going good and until I reach the part where Angular Routing was supposed to happened.
一切都很好,直到我到达了应该进行角路由的那部分。 I could not find the error.
我找不到错误。 If anybody could give me a hand that wold be great!
如果有人可以帮我,那太棒了! Here is the plunker .
这是the 子 。
Here's the app (app3.js): 这是应用程序(app3.js):
var app = angular.module('futbol', ['ui.router'])
app.factory('jugadores', [function(){
var o = {
jugadores: []
/*jugadores: [
{nombre: 'Hernan', goles: 5},
{nombre: 'Ricardo', goles: 2},
{nombre: 'Tiago', goles: 15},
{nombre: 'Marcelo', goles: 9},
{nombre: 'German', goles: 4}
];*/
};
return o;
}])
app.controller('MainCtrl', [
'$scope',
'jugadores',
function($scope,jugadores){
$scope.jugadores = jugadores.jugadores;
$scope.test = 'HOLA!';
$scope.addJugador = function(){
$scope.jugadores.push({nombre: $scope.nombre, goles: 0});
$scope.nombre = '';
};
$scope.incrementGoles = function(jugador) {
jugador.goles += 1;
};
}]);
app.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/home.html',
controller: 'MainCtrl'
});
$urlRouterProvider.otherwise('home');
}]);
Go to plunker link to see the HTML. 转到链接链接查看HTML。
Thanks 谢谢
There is updated and running plunker 有更新且正在运行的插件
To make it running we need a root anchor/target ui-view=""
for our state: 为了使它运行,我们需要一个root anchor / target
ui-view=""
作为状态:
<body ng-app="futbol">
<div ui-view=""></div>
And also, this should be the otherwise (not just 'home') : 而且,这应该是其他方式(不仅仅是“家”) :
$urlRouterProvider.otherwise('/home');
It says which url should be used as default... 它说应该使用哪个URL作为默认值...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.