1
我想用UI邏輯擴展一些模塊。具有功能的角度擴展模塊(最佳實踐)
例如 - 簡單模塊,誰可以添加警報和清除警報。 並在其他模塊中使用它。在另一個模塊
var MessageBox = angular.module('MessageBox', ['ui.bootstrap']);
MessageBox.controller('MessageBoxController', ['$rootScope', function ($rootScope) {
$rootScope.alerts = [];
$rootScope.addAlert = function (alert) {
$rootScope.alerts.push(alert);
};
$rootScope.closeAlert = function (index) {
$rootScope.alerts.splice(index, 1);
};
}]);
末使用:
var App = angular.module('App', ['MessageBox']);
...和控制器:
console.log("$scope.alerts : " + $scope.alerts);
addAlert({type: 'success', msg: 'Message.'});
它是用於擴展模塊和功能的最佳做法?
P.S.請排列這個問題,我不能獲得15的聲望。謝謝!
[Angular best practices](http://stackoverflow.com/q/20802798/1959948) – Dalorzo 2014-08-30 18:02:16