定義的angularjs控制器我想使用模塊模式是這樣來定義我的控制器:檢索使用模塊模式
(function(ng, app) {
// Controller constructor.
function Controller($scope) {
this.scope = $scope;
this.scope.fmembers = [
{
name: 'Member 1',
role: 'Head of Family',
age: 55
},
{
name: 'Member 2',
role: 'Brother of Head of Family',
age: 51
}
];
Controller.prototype = {
getFMembers: function() {
return this.scope;
}
};
return(this);
}
// Define the Controller as the constructor function.
app.controller('ftreeController', Controller);
})(angular, anmDesktop);
如果我這樣做,我怎麼能檢索信息的模塊控制器(ftreeController)?例如,我想在app.config中使用freeController在routeprovider:
$routeProvider.when('/view2', {
templateUrl: 'partials/partial2.html',
controller: ftreeController'
});
在上述routeprovider,我得到一個錯誤(ftreeController沒有定義...)
謝謝。
感謝您指點的方式。我試圖避免通過名稱暴露控制器(比如angular-seed生成的控制器)。很明顯,解決方案中的應用程序的方法控制器方法使我可以做得更好,也不需要定義命名對象。再次感謝 –
@ Ya.Perelman很高興我能幫忙。我更喜歡萌芽處理模塊,而不是種子:https://github.com/thedigitalself/angular-sprout –