@@ -3,28 +3,61 @@ angular-errors-directive
3
3
4
4
AngularJS user error feedback directive.
5
5
6
- Usage
7
- -----
6
+ Install
7
+ -------
8
+ ** Requires Twitter Bootstrap**
9
+ ``` bower install angular-errors-directive ```
8
10
9
- * ** Requires Twitter Bootstrap**
11
+ Include
12
+ -------
13
+ Include the directive in your pages as:
14
+ ```
15
+ <awesome-error target="'pageName'"></awesome-error>
16
+ ```
17
+ where ``` pageName ``` is a unique id.
10
18
11
- * Include the directive in your template as,
12
- * <awesome-error target="'settingsPage'"></awesome-error> where, target defines the error directive you are targetting.
13
- * Then, broadcast or emit the message from controllers or directives. e.g.
14
- * $scope.$broadcast(errorState, target, error); // template of broadcast
15
- * $scope.$broadcast('show error', 'settingsPage', 'INVALID_DATE'); // to show error msg
16
- * $scope.$emit('hide error', 'settingsPage'); // to hide error msg
17
- * $scope.$emit('show success', 'settingsPage', 'TWEET_POSTED'); // to show success msg
18
- * $scope.$emit('hide success', 'settingsPage'); // to hide success msg
19
+ Messages
20
+ --------
21
+ You need to keep all your error messages in a JSON file ``` errors_list.json ``` .
19
22
20
- You need to keep all your error messages in a JSON file 'errors_list.json'. e.g.
23
+ Add a default error message ``` Undefined ``` which will be called whenever a key is not found.
24
+
25
+ Example:
21
26
```
22
27
{
23
28
"INVALID_DATE" : "Please enter a valid date",
24
29
"username_not_found" : "Sorry, This username is already taken",
25
- "TWEET_POSTED": "Tweet was posted successfully"
30
+ "TWEET_POSTED": "Tweet was posted successfully",
31
+ "Undefined": "Oops, something went wrong"
26
32
}
27
33
```
28
-
29
- Uppercase error messages represent errors from server while lowercase error messages represent
34
+ Convention: uppercase error messages represent errors from server while lowercase error messages represent
30
35
errors from client side.
36
+
37
+ Broadcast a Message
38
+ -------------------
39
+ Broadcast messages as follows:
40
+ ```
41
+ $scope.$broadcast(type, target, error);
42
+ ```
43
+ where
44
+ * ** type** is the type of broadcast (see below),
45
+ * ** target** is the unique id used while declaring the directive in your html file,
46
+ * ** error** is the error key pointing to an error message value in ``` errors_list.json ``` .
47
+
48
+ Types of Broadcast
49
+ ------------------
50
+ ** show error / hide error**
51
+
52
+ To show and hide an error message. Example:
53
+ ```
54
+ $scope.$broadcast('show error', 'settingsPage', 'INVALID_DATE');
55
+ $scope.$emit('hide error', 'settingsPage');
56
+ ```
57
+ ** show success / hide success**
58
+
59
+ To show and hide a success message. Example:
60
+ ```
61
+ $scope.$emit('show success', 'settingsPage', 'TWEET_POSTED');
62
+ $scope.$emit('hide success', 'settingsPage');
63
+ ```
0 commit comments