Подтвердить что ты не робот

Получение "не удалось разрешить... из состояния..." при использовании вложенных маршрутов angularjs

Я новичок в angularjs, и я хочу использовать вложенные ui-маршруты для своего приложения. Некоторые фрагменты кода...

profile.html

<div class="row">
<div class="dl-horizontal" id="information">

    <div class="col-md-8 col-md-offset-2">

    <!-- edit button -->
    <div style="margin-bottom: 15px">   
        <div class="button" style="margin-top:5px" style="float:left">
            <button type="button" class="btn btn-primary" ui-sref="edit_profile" ng-click="populate()"><span class="glyphicon glyphicon-pencil"></span> Edit Profile</button>
        </div>
    </div>

client_UI.js

//object for routing
var route = angular.module('route', ["ui.router"])

// configure the routing        
route.config(function($stateProvider, $urlRouterProvider, $locationProvider) {

    // send to profile page
    $urlRouterProvider.otherwise("/profile");

    $stateProvider

    // route for personal info
    .state('profile', {
        url: "/profile", 
        templateUrl : "profile_area/profile.html" , 
        controller : 'profileController'
    })

edit.html

<script src="Scripts/angular-ui-bootstrap.js"></script>


    <!-- title -->
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h2 class="modal-title"> Editing Profile</h2>
    </div>

    <div class="modal-body">
        <form role="form" id="myForm">

            <!-- Name -->
        <div class="panel panel-default">
        <div class="panel-body">
            <div class="form-group">
                <label for="name">Name &nbsp;</label>
                <input placeholder="{{infos.Name}}" id="name" type="text" ng-model="name">
            </div>

profile.js

//object for routing
var route = angular.module('route', ["ui.router"])

// configure the routing        
route.config(function($stateProvider, $urlRouterProvider, $locationProvider) {

$stateProvider

//route for edit page
.state('edit_profile', {
    url: "/edit_profile",
    templateURL : "edit/edit_profile.html" ,
    controller : 'editController'
})
});

route.controller('editController' ["$scope", "$resource", function($scope, $resource) {

// resource objects
var profile = $resource($scope.apicall + "/api/userprofile/", {Userid:$scope.userid}, {'post':{method: 'POST'}});
var edit = new profile();

и это вид (index.html)...

       <!-- route veiw -->
    <div class="container" id="route" style="width:90%">
            <div ui-view></div>
    </div>

    <!-- Footer -->
    <footer></footer>

Я получаю сообщение об ошибке с консоли, которая говорит: "Не удалось разрешить" edit_profile "из профиля состояния", а edit.html должен быть дочерним состоянием profile.html. Я использую ui-routing в angularjs. Я хочу, чтобы иметь возможность щелкнуть кнопку в файле profile.html, который изменит состояние на edit_profile и будет отображаться в ui-view в index.html. Любые предложения по устранению этого или есть еще один простой способ сделать это?

4b9b3361

Ответ 1

В этом случае angular сообщает нам: я просто не могу найти состояние edit_profile. Я создал рабочий пример здесь

Причина в том, что нам действительно нужно загрузить 2 js файла:

  • profile.js
  • client_UI.js

оба из них должны быть загружены, но оба из них не могут объявить один и тот же модуль:

var route = angular.module('route', ["ui.router"])

один из них должен быть другим или просто не объявлять, а потреблять модуль:

// client_UI.js
var route = angular.module('client_ui', ["ui.router"])
// profile.js
var route = angular.module('route', ["ui.router", "client_ui"])

или оба могут быть в одном модуле:

// client_UI.js
var route = angular.module('route', ["ui.router"])
// profile.js
var route = angular.module('route')

Убедитесь, что все рабочие здесь