невозможно получить содержание URL с помощью ui.router - PullRequest
0 голосов
/ 09 мая 2018

мой HTML-код

<!doctype Html>
<html lang="en">
<head >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></link>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.16/angular-ui-router.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="first.js"></script>

</head>
<body ng-app="myApp">
<a href="first">firstname</a>
<div ui-view></div>
</body>

и мой JS падает здесь

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

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

     $stateProvider.state('home', {
            url: 'first',
            templateUrl: 'msg.html '
        })
});

и msg.html

<div >

hello world
</div>

Я не знаю, почему я не могу получить URL-адрес, он выдает ошибку, как объект не найден, помощь приветствуется

1 Ответ

0 голосов
/ 09 мая 2018

Использовать, ui-sref вместо href

 <a ui-sref="home">firstname</a>

Так будет код,

index.html:

<!doctype Html>
<html lang="en">

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>

    <script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <script src="script.js"></script>

</head>

<body ng-app="myapp">

    <a ui-sref="home">firstname</a>
    <div ui-view></div>
</body>

</html>

Сценарий:

(function(){
    var app = angular.module('myapp', ["ui.router"]);

    app.config(function($stateProvider, $urlRouterProvider) {
        $stateProvider.state('home', {
            url: 'first',
            templateUrl: 'msg.html '
        })
    });
})();

msg.html

<div>
  Hello World
</div>

Вот документация

Пожалуйста, отметьте это ДЕМО

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...