すべてのコントローラー呼び出しの前にモデル/変数を設定するにはどうすればよいですか?
現在、ページにエラーメッセージを設定するのに役立つ次のサービスがあります(LiveScriptのコード):
angular.module "project.services",
.factory "Message", ($rootScope) ->
{
error : !(msg) -> $rootScope.error = msg
success : !(msg) -> $rootScope.success = msg
clear : !(msg) ->
$rootScope.error = ''
$rootScope.success = ''
}
そして、私のindex.html
テンプレートで:
<div ng-show="error" class="alert alert-error">{{error}}</div>
<div ng-show="success" class="alert alert-success">{{success}}</div>
<div ng-view>
しかし、それを使用するには、すべてclear
のコントローラーでメソッドを呼び出す必要があります。そうしないと、エラーが画面に残ります。
@SomeController = !($scope, $http, Message) ->
Message.clear() # <--- have to do this
... rest of the controller code
if some-error condition
Message.error("Could not do this")
else
Message.success("Success!")
この明確なステップを自動化する方法はありますか?