AngularJs 多个控制器,ng-click 和 ng-view
AngularJs multiple Controllers, ng-click and ng-view
这可能是我遗漏了一些东西或者在教程中理解错误,所以请耐心等待。
我有我的应用程序....
var shepApp = angular.module('shepApp', [
'ngRoute',
'ui-notification',
'shepControllers',
'shepFilters',
'shepServices'
]);
shepApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/galaxies', {
templateUrl: "partials/galaxies.html",
controller: 'GalaxyListCtrl'
}).
}]);
我的控制器是这样的....
var shepControllers = angular.module('shepControllers', []);
shepControllers.controller('GalaxyListCtrl', ['$scope', '$location', 'Notification', 'Galaxy', function($scope, $location, Notification, Galaxy) {
$scope.galaxys = Galaxy.query();
$scope.blah = function(){
alert(123);
}
}]);
shepControllers.controller('GalaxyDetailCtrl', ['$scope', '$routeParams', '$location', 'Notification', 'Galaxy', function($scope, $routeParams, $location, Notification, Galaxy) {
$scope.galaxy = Galaxy.get({slug: $routeParams.slug});
}]);
我的 galaxies.html
部分包含以下 HTML 使用 ng-click
。
<button ng-click="blah"></button>
我的想法是,当我的路线是 /galaxies
并且正在使用的控制器是 GalaxyListCtrl
时,点击事件的 blah
函数将被暴露 - 但永远不会触发警报完全没有。
我想我在这一切组合在一起的方式中遗漏了一些东西。
调用不带参数的函数是使用函数名称后跟圆括号完成的:
ng-click="blah()"
这可能是我遗漏了一些东西或者在教程中理解错误,所以请耐心等待。
我有我的应用程序....
var shepApp = angular.module('shepApp', [
'ngRoute',
'ui-notification',
'shepControllers',
'shepFilters',
'shepServices'
]);
shepApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/galaxies', {
templateUrl: "partials/galaxies.html",
controller: 'GalaxyListCtrl'
}).
}]);
我的控制器是这样的....
var shepControllers = angular.module('shepControllers', []);
shepControllers.controller('GalaxyListCtrl', ['$scope', '$location', 'Notification', 'Galaxy', function($scope, $location, Notification, Galaxy) {
$scope.galaxys = Galaxy.query();
$scope.blah = function(){
alert(123);
}
}]);
shepControllers.controller('GalaxyDetailCtrl', ['$scope', '$routeParams', '$location', 'Notification', 'Galaxy', function($scope, $routeParams, $location, Notification, Galaxy) {
$scope.galaxy = Galaxy.get({slug: $routeParams.slug});
}]);
我的 galaxies.html
部分包含以下 HTML 使用 ng-click
。
<button ng-click="blah"></button>
我的想法是,当我的路线是 /galaxies
并且正在使用的控制器是 GalaxyListCtrl
时,点击事件的 blah
函数将被暴露 - 但永远不会触发警报完全没有。
我想我在这一切组合在一起的方式中遗漏了一些东西。
调用不带参数的函数是使用函数名称后跟圆括号完成的:
ng-click="blah()"