I'm new to angularjs and I want to use nested ui-routes for my application. Some code snippets ...
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">×</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 </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();
and this is the view (index.html) ...
<!-- route veiw -->
<div class="container" id="route" style="width:90%">
<div ui-view></div>
</div>
<!-- Footer -->
<footer></footer>
I'm getting an error from the console that says, Could not resolve "'edit_profile' from state 'profile'" and edit.html is supposed to be the child state of profile.html. I'm using ui-routing in angularjs. I want to be able to click a button in the profile.html that will change the state to edit_profile and will be displayed in the ui-view in index.html. Any suggestions on how to fix this or is there another easy way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…