Javascript angular-index.html仅识别默认路由中定义的函数
我在角度上有接线问题。 在我的index.html中,每个选项卡都有一个导航栏,上面有ng click=“go(“”)” “go”是在我的每个控制器中定义的函数Javascript angular-index.html仅识别默认路由中定义的函数,javascript,angularjs,Javascript,Angularjs,我在角度上有接线问题。 在我的index.html中,每个选项卡都有一个导航栏,上面有ng click=“go(“”)” “go”是在我的每个控制器中定义的函数 var sheepApp= angular.module('sheepApp', [ 'ui.bootstrap', 'ngRoute', 'firebase' ]); sheepApp.config(['$routeProvider', function($routeProvider) { $ro
var sheepApp= angular.module('sheepApp', [
'ui.bootstrap',
'ngRoute',
'firebase'
]);
sheepApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'pages/home.html',
controller: 'homeCtrl'
}).
when('/vision', {
templateUrl: 'pages/vision.html',
controller: 'visionCtrl'
}).
when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutCtrl'
}).
when('/gallery', {
templateUrl: 'pages/gallery.html',
controller: 'galleryCtrl'
}).
when('/videos', {
templateUrl: 'pages/videos.html',
controller: 'videosCtrl'
}).
otherwise({
redirectTo: '/home'
});
}]);
问题是,“go”函数(以及所有其他函数)只有在我现在处于定义为“others”(在我的例子中是“home”)的路径中时才被识别
为什么会发生
谢谢
编辑
ctrls.js中定义的我的所有Conntoller
其中一个CTRL的示例:
sheepApp.controller('joinUsCtrl', ['$scope','$rootScope','$location',
function ($scope, $rootScope,$location) {
$rootScope.go = function ( path ) {
$location.path( path );
};
$rootScope.isActive = function(tabName){
return $location.path() == tabName;
};
$scope.he = he;
}]);
这是$rootScope中的一个工作方法go的示例。 检查您的chrome控制台,如果抛出错误,则控制器未添加此行抛出错误$scope.he=he;go功能不会改变。(以您的示例为基础,稍作修改)
var sheepap=angular.module('sheepap'[
“ngRoute”
]);
sheepApp.config(['$routeProvider',
函数($routeProvider){
$routeProvider。
当(“/home”{
模板:“{{controller.name}}”,
控制器:“homeCtrl”
}).
当(“/vision”{
模板:“{{controller.name}}”,
控制器:“visionCtrl”
}).否则({
重定向到:'/home'
});
}]);
sheepApp.controller('homeCtrl',['$scope','$rootScope','$location',',
函数($scope、$rootScope、$location){
$rootScope.go=函数(路径){
警惕(“在家工作”);
};
$rootScope.asd={asd:“asd”};
$rootScope.isActive=函数(tabName){
返回$location.path()==tabName;
};
$scope.controller={name:'home'}
}]).controller('visionCtrl'、['$scope'、'$rootScope'、'$location',
函数($scope、$rootScope、$location){
$rootScope.go=函数(路径){
警惕(“在视觉中工作”);
};
$rootScope.asd={asd:“asd”};
$rootScope.isActive=函数(tabName){
返回$location.path()==tabName;
};
$scope.controller={name:'vision'}
}]);代码>
根镜函数
您需要显示控制器或定义go功能的部件。这是不够的信息。你在索引中包含了其他控制器文件吗?就像我看到你在使用angular route一样,我假设你在index.html中有一个ngview,并且控制器的范围仅在该ngview(路由中的模板)内工作,如果你在ngview之外有go()函数,那么永远不会工作。尝试在ngview之前使用function@JesúsQuintana-所以我不理解为什么在路线“家”(定义为我的oterwise选项)中它会起作用,我用更多的数据编辑我的问题