Explore the simple application of ui.route in AngularJs

高洛峰
Release: 2016-12-06 15:46:54
Original
1244 people have browsed it

html page code

   
  
  
Copy after login

The ui.router.js file that needs to be referenced

Copy after login

app.js

Inject UI-Router as a dependency of the web application into the main program:

url The :url option will specify a URL for the application's state based on the state in which the user is browsing the application (the address displays the link). In this way, the effect of deep linking can be achieved when browsing the application.

var myApp = angular.module('myApp', ['ui.router']); myApp.config(['$stateProvider', '$urlRouterProvider', routeConfig]); function routeConfig($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise(''); $stateProvider.state('competition', { url: '/competition', templateUrl: '/competition.html', controller: 'competitionController' }).state('competition.detail', { url: '/competition-detail', templateUrl: '/competition-detail.html', controller: 'competitionDetailController' }).state.('competition.enrollForm',{ url: '/competition.enrollForm', templateUrl: 'competition-enrollFrom.html', controller: 'enrollFromController' }).state.('competition.comments',{ url: '/competition-comments', templateUrl: 'competition-comments.html', controller: 'commentsController' }).state('competition.login',{ url: '/competition-login', views: { 'login@': { templateUrl: 'competition-login.html', controller: 'loginController' } } }).state('competition.enroll',{
  url: '/competition-enroll',
views: {
    'enroll@': {
     templateUrl: 'competition-enroll.html',
      controller: 'enrollController'
}
}
})
}
Copy after login

It should be noted that: ui.router uses $stateProvider, and ngRoute uses $routeProvider.

$state.go

$state.go(to, [,toParams],[,options])

The formal parameter to is of string type, which must be used. Use "^" or "." to indicate relative paths;

The formal parameter toParams is nullable, and the type is an object;

The formal parameter options is nullable, and the type is an object. The fields include: location is a bool type and the default is true, inherit is a bool type and the default is true, and relative is an object and the default is

$state. $current, notify is bool type and defaults to true, reload is bool type and defaults to false

$state.go('photos.detail')

$state.go('^') to the previous level, such as from photo.detail to photo

$state.go('^.list') to adjacent state, such as from photo.detail to photo.list

$state.go('^.detail.comment') to Grandchild-level state, such as from photo.detail to photo.detial.comment


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!