angularjs 路由配置controller 点击跳转页面控制器被调用两次 该如何解决?
varroutapp4=angular.module('routerApp4',['ui.router']);routapp4.config(function($stat...
var routapp4 = angular.module('routerApp4',['ui.router']);
routapp4.config(function($stateProvider,$urlRouterProvider){
$urlRouterProvider.otherwise('/producers');
$stateProvider.state('producers', {
url: '/producers',
templateUrl: 'tpls3/producers.html',
controller: 'ProducersCtrl'
})
.state('producer', {
url: '/producer/:producerId',
templateUrl: 'tpls3/producer.html',
controller: 'ProducerCtrl'
})
.state('home',{
url:'/home/:homeId',
templateUrl:'tpls3/home.html',
controller:'homeCtrl'
})
});
routapp4.controller('ProducersCtrl', function ($scope, $state) {
$scope.toProducer = function(producerId) {
$state.go('producer', {producerId: producerId});
};
});
routapp4.controller('ProducerCtrl', function ($scope, $state, $stateParams) {
$scope.toHome = function(homeId) {
$state.go('home', {homeId: homeId}); //跳路由
};
var producerId = $stateParams.producerId;
});
routapp4.controller('homeCtrl', function ($scope, $state, $stateParams,$timeout) {
var homeId = $stateParams.homeId;
$scope.toback = function(){
window.history.back();
}
$timeout(function () {
alert("1");
}, 2000);
});
(点击时跳转页面时调用两次controller 进入跳转的页面刷新时只调用一次 html文件没有用ng-controller 求大神帮忙) 展开
routapp4.config(function($stateProvider,$urlRouterProvider){
$urlRouterProvider.otherwise('/producers');
$stateProvider.state('producers', {
url: '/producers',
templateUrl: 'tpls3/producers.html',
controller: 'ProducersCtrl'
})
.state('producer', {
url: '/producer/:producerId',
templateUrl: 'tpls3/producer.html',
controller: 'ProducerCtrl'
})
.state('home',{
url:'/home/:homeId',
templateUrl:'tpls3/home.html',
controller:'homeCtrl'
})
});
routapp4.controller('ProducersCtrl', function ($scope, $state) {
$scope.toProducer = function(producerId) {
$state.go('producer', {producerId: producerId});
};
});
routapp4.controller('ProducerCtrl', function ($scope, $state, $stateParams) {
$scope.toHome = function(homeId) {
$state.go('home', {homeId: homeId}); //跳路由
};
var producerId = $stateParams.producerId;
});
routapp4.controller('homeCtrl', function ($scope, $state, $stateParams,$timeout) {
var homeId = $stateParams.homeId;
$scope.toback = function(){
window.history.back();
}
$timeout(function () {
alert("1");
}, 2000);
});
(点击时跳转页面时调用两次controller 进入跳转的页面刷新时只调用一次 html文件没有用ng-controller 求大神帮忙) 展开
1个回答
2017-06-29
展开全部
实在是不能对jquery的ajax方法和基于页面dom的各种取值、传值方法满意(虽然jquery已经解救过我一次了),刚好手上这个项目用jquery的方法写了一半,决定试试很久以前自学的angularJS,把现在项目中jquery得部分用angularJS重写一遍。写的时候
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询