There is the following code:
angular.module('app', ['app.animators', 'app.events', 'app.hotel', 'app.controllers', 'app.services', 'ui.router', 'templates', 'ngResource', 'ngCookies', 'ui.bootstrap', 'ngImgCrop', 'angularjs-dropdown-multiselect']).config(['$httpProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider', ($httpProvider, $locationProvider, $stateProvider, $urlRouterProvider) ->
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
$urlRouterProvider.otherwise("/404")
$stateProvider.state('signIn'
url: '/admin/signin'
controller: 'SignInController'
templateUrl: 'signin.html'
)
$locationProvider.html5Mode(true)
])
It works good, but I change it to the following code:
angular.module('app', ['app.animators', 'app.events', 'app.hotel', 'app.controllers', 'app.services', 'ui.router', 'templates', 'ngResource', 'ngCookies', 'ui.bootstrap', 'ngImgCrop', 'angularjs-dropdown-multiselect']).config(['$httpProvider', '$locationProvider', '$stateProvider', '$urlRouterProvider', ($httpProvider, $locationProvider, $stateProvider, $urlRouterProvider) ->
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content')
$urlRouterProvider.otherwise("/404")
$stateProvider.state('admin.signIn'
url: '/admin/signin'
controller: 'SignInController'
templateUrl: 'signin.html'
).state('admin'
abstract: true
)
$locationProvider.html5Mode(true)
])
It doesn't work, i.e. I enter the address 'http://localhost/admin/signin', browser is loading, but I don't get 'signin.html' template. I need to use 'admin' state in order to use a 'resolve' function for all child states (my example is not complete). What's the trouble ? Thanks in advance!
Almost each parent should have a template - the one which will be a target for its child. There is a working plunker.
So just adding this line to the parent definition: template: "<div ui-view></div>" - will make that code working:
.state('admin', {
abstract: true,
template: "<div ui-view></div>"
})
What happened is - child does have its target, the anchor where it could be injected.
There could be other solution, e.g. child is targeting the root ui-view="" ... but above solution is appropriate... See View Names - Relative vs. Absolute Names, check this answer and its plunker with more examples of absolute name targeting
Check it in action here
Related
I have a problem to use $rootScope.$on in AngularJS, I try to call alert, but unsuccess, nothing error in console, I generate this project use yeoman generator, I don't know why, this is my script, please correct my script.
'use strict';
angular
.module('siapApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'ui.router',
'ui.bootstrap'
])
.config(['$stateProvider', '$locationProvider', '$urlRouterProvider', '$qProvider',
function ($stateProvider, $locationProvider, $urlRouterProvider, $qProvider) {
$stateProvider
.state('main', {
url: '/',
views: {
'content#': {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
}
}
})
.state('about', {
url: '/about',
views: {
'content#': {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
}
}
})
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise('/');
$qProvider.errorOnUnhandledRejections(false);
}])
.run(['$rootScope', '$state', '$stateParams',
function($rootScope, $state, $stateParams) {
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
alert('success'); /*cannot call alert*/
});
}
]);
Please anyone help me.
Thanks.
This should work in any case. The only thing I can suspect is you don't have ui-view directive on your index.html page.
<ui-view></ui-view>
I feel like I'm so close, but I get hung up on why this setup isn't working for me. https://github.com/jaruesink/first_meteor
Thanks for anyone who can help out with this, I'm just trying to learn and have fun with a new project.
scripts/_main.coffee
#App = angular.module('App', [
'angular-meteor'
'ngMaterial'
'ui.router'
])
#App.config [
'$interpolateProvider'
($interpolateProvider) ->
$interpolateProvider
.startSymbol '[['
.endSymbol ']]'
]
scripts/router.coffee
#App.config [
'$stateProvider', '$urlRouterProvider', '$locationProvider'
($stateProvider, $urlRouterProvider, $locationProvider) ->
$locationProvider.html5Mode true
$urlRouterProvider.otherwise '/home'
$stateProvider.state('home'
url: '/home'
templateUrl: UiRouter.template 'home'
)
]
index.jade
head
title App
base(href="/")
body(ng-app="App")
div.container
h1 If 2 + 5 = [[2+5]], then I'm working :-)
p but why isn't the router below showing up?
div(ui-view)
views/home/home.jade
template(name='home')
section#home
div.container
h1 hello world, 1 + 2 = [[1+2]]
but here is what happens (the highlighted ui-view repeats the header code with all of the scripts again too)
In your file router.coffee, On the templateUrl attribute you just need to mention the name of template like below:
#App.config [
'$stateProvider', '$urlRouterProvider', '$locationProvider'
($stateProvider, $urlRouterProvider, $locationProvider) ->
$locationProvider.html5Mode true
$urlRouterProvider.otherwise '/home'
$stateProvider.state('home'
url: '/home'
templateUrl: 'home'
)
]
Your application will work fine
I am trying to add the detail view in Angularjs
this is my app.js file
angular.module('frontendApp', ['ngAnimate', 'ngCookies', 'ngResource', 'ui.router', 'ngSanitize', 'ngTouch']).config ($stateProvider) ->
$stateProvider.state('home',
url: "/"
templateUrl: "home.html"
).state('services',
url: "/services"
templateUrl: "services.html"
).state('detail',
url: "/detail"
templateUrl: "detail.html"
)
And I created the file detail.html, but this is not working, I can't access the view in http://localhost:3000/#/detail. I have to do something else ?
How can I share the scope with angular ui router ? I tried this :
angular.module('myApp').controller('detailCtrl', ['$scope',
function($scope) {
$scope.test=$scope.$parent.services;
angular
.module('myApp', ['ngAnimate', 'ngCookies', 'ngResource'
, 'ui.router', 'ngSanitize', 'ngTouch'])
.config ($stateProvider) ->
$stateProvider.state('home',
url: "/"
templateUrl: "home.html"
).state('services',
url: "/services"
templateUrl: "services.html"
).state('services.detail',
url: "/detail/"
templateUrl: "detail.html"
)
in servicesCtrl :
$scope.services = getServices.query();
I'm using the ngClip plugin to attempt to add a "copy to clipboard" option to my web app. I am also using the ui-router in my module config. The problem is that when I add the ngClipProvider dependency to my .config, the $urlRouterProvider becomes undefined. When I remove it, $urlRouterProvider is an object again. Below is my code:
var app = angular.module('app',['ui.router', 'ui.date', 'ngAnimate', 'angular-loading-bar', 'orders-directives', 'orders-controllers', 'orders-services', 'orders-factories', 'ngClipboard']);
//Config
app.config(['ngClipProvider', function($stateProvider, $urlRouterProvider, ngClipProvider){
$urlRouterProvider.otherwise('/');
$stateProvider.state('/', {
url: '/',
templateUrl: 'templates/admin-view.html',
controller: 'ordersController as ordersCtrl'
}).state('order', {
url: '/order/:ordernum?id',
templateUrl: 'templates/order-details.html',
controller: 'orderDetailsController as orderCtrl'
}).state('export', {
url: '/export',
templateUrl: 'templates/review-export.html',
controller: 'reviewExportController as reviewExportCtrl'
});
//ngClipProvider.setPath("../plugins/ZeroClipboard/ZeroClipboard.swf");
}]);
If I remove the "['ngClipProvider .....]" section and the "ngClipProvider" from the function parameters, everything works. As is above, $urlRouterProvider is null.
You are messing with inline dependency injection array , missed to add '$stateProvider', '$urlRouterProvider' before 'ngClipProvider'
app.config(['$stateProvider', '$urlRouterProvider', 'ngClipProvider',
function($stateProvider, $urlRouterProvider, ngClipProvider){
//code here...
}])