Skip to content

Commit 57a3349

Browse files
author
赵可
committed
Merge remote-tracking branch 'upstream/master'
2 parents b937860 + 80fb1e8 commit 57a3349

File tree

4 files changed

+127
-56
lines changed

4 files changed

+127
-56
lines changed

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,20 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
367367

368368
Note: When creating watches in a controller using `controller as`, you can watch the `vm.*` member using the following syntax. (Create watches with caution as they add more load to the digest cycle.)
369369

370+
```html
371+
<input ng-model="vm.title"/>
372+
```
373+
370374
```javascript
371-
$scope.$watch('vm.title', function(current, original) {
372-
$log.info('vm.title was %s', original);
373-
$log.info('vm.title is now %s', current);
374-
});
375+
function SomeController($scope, $log) {
376+
var vm = this;
377+
vm.title = 'Some Title';
378+
379+
$scope.$watch('vm.title', function(current, original) {
380+
$log.info('vm.title was %s', original);
381+
$log.info('vm.title is now %s', current);
382+
});
383+
}
375384
```
376385

377386
### Bindable Members Up Top
@@ -539,7 +548,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
539548
```
540549
541550
### Defer Controller Logic
542-
###### [Style [Y035](#style-y036)]
551+
###### [Style [Y035](#style-y035)]
543552
544553
- Defer logic in a controller by delegating to services and factories.
545554
@@ -550,31 +559,49 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
550559
*Why?*: Removes dependencies and hides implementation details from the controller.
551560
552561
```javascript
562+
553563
/* avoid */
554-
function Order($http, $q) {
564+
function Order($http, $q, config, userInfo) {
555565
var vm = this;
556566
vm.checkCredit = checkCredit;
567+
vm.isCreditOk;
557568
vm.total = 0;
558569

559-
function checkCredit() {
560-
var orderTotal = vm.total;
561-
return $http.get('api/creditcheck').then(function(data) {
562-
var remaining = data.remaining;
563-
return $q.when(!!(remaining > orderTotal));
564-
});
570+
function checkCredit() {
571+
var settings = {};
572+
// Get the credit service base URL from config
573+
// Set credit service required headers
574+
// Prepare URL query string or data object with request data
575+
// Add user-identifying info so service gets the right credit limit for this user.
576+
// Use JSONP for this browser if it doesn't support CORS
577+
return $http.get(settings)
578+
.then(function(data) {
579+
// Unpack JSON data in the response object
580+
// to find maxRemainingAmount
581+
vm.isCreditOk = vm.total <= maxRemainingAmount
582+
})
583+
.catch(function(error) {
584+
// Interpret error
585+
// Cope w/ timeout? retry? try alternate service?
586+
// Re-reject with appropriate error for a user to see
587+
});
565588
};
566589
}
567590
```
568591
569592
```javascript
593+
570594
/* recommended */
571595
function Order(creditService) {
572596
var vm = this;
573597
vm.checkCredit = checkCredit;
598+
vm.isCreditOk;
574599
vm.total = 0;
575600

576601
function checkCredit() {
577-
return creditService.check();
602+
return creditService.isOrderTotalOk(vm.total)
603+
.then(function(isOk) { vm.isCreditOk = isOk; })
604+
.catch(showServiceError);
578605
};
579606
}
580607
```

i18n/PT-BR.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,13 +1535,13 @@ ou *Minificação e Anotação*
15351535
> Nota: Apartir do AngularJS 1.3 use o parâmetro `ngStrictDi` da diretiva [`ngApp`](https://docs.angularjs.org/api/ng/directive/ngApp). Quando presente, o injetor será criado no modo "strict-di" fazendo com que a aplicação falhe ao tentar invocar funções que não usem anotação explícita de função (elas podem não ser seguras para minificação). Informação de debug será logada no console para ajudar a rastrear o código ofensivo.
15361536
`<body ng-app="APP" ng-strict-di>`
15371537
1538-
### Use Gulp or Grunt for ng-annotate
1538+
### Utilize Gulp ou Grunt para o ng-annotate
15391539
1540-
- Use [gulp-ng-annotate](https://www.npmjs.org/package/gulp-ng-annotate) or [grunt-ng-annotate](https://www.npmjs.org/package/grunt-ng-annotate) in an automated build task. Inject `/* @ngInject */` prior to any function that has dependencies.
1540+
- Utilize [gulp-ng-annotate](https://www.npmjs.org/package/gulp-ng-annotate) ou [grunt-ng-annotate](https://www.npmjs.org/package/grunt-ng-annotate) para tarefas de build automatizadas. Injete `/* @ngInject */` antes de qualquer função que tenha dependências.
15411541
1542-
*Why?*: ng-annotate will catch most dependencies, but it sometimes requires hints using the `/* @ngInject */` syntax.
1542+
*Por que?*: ng-annotate vai capturar todas as dependências, mas as vezes requer dicas utilizando a sintaxe `/* @ngInject */` .
15431543
1544-
The following code is an example of a gulp task using ngAnnotate
1544+
O código abaixo é um exemplo de uma task Gulp utilizando ngAnnotate
15451545
15461546
```javascript
15471547
gulp.task('js', ['jshint'], function() {
@@ -1570,11 +1570,11 @@ ou *Minificação e Anotação*
15701570
15711571
### decorators
15721572
1573-
- Use a [decorator](https://docs.angularjs.org/api/auto/service/$provide#decorator), at config time using the [`$provide`](https://docs.angularjs.org/api/auto/service/$provide) service, on the [`$exceptionHandler`](https://docs.angularjs.org/api/ng/service/$exceptionHandler) service to perform custom actions when exceptions occur.
1573+
- Utilize um [decorator](https://docs.angularjs.org/api/auto/service/$provide#decorator), no seu configutilizando o serviço [`$provide`](https://docs.angularjs.org/api/auto/service/$provide) , no serviço [`$exceptionHandler`](https://docs.angularjs.org/api/ng/service/$exceptionHandler) para realizar ações customizadas quando um erro ocorrer.
15741574
1575-
*Why?*: Provides a consistent way to handle uncaught AngularJS exceptions for development-time or run-time.
1575+
*Por que?*: Fornece um caminho consistente para manipular erros não tratados pelo AngularJS em tempo de desenvolvimento ou run-time.
15761576
1577-
Note: Another option is to override the service instead of using a decorator. This is a fine option, but if you want to keep the default behavior and extend it a decorator is recommended.
1577+
Nota: Outra opção é sobrescrever o serviço ao invés de utilizar um decorator. Esta é uma boa opção, mas se você quer manter o comportamento padrão e estender o decorator é recomendado.
15781578
15791579
```javascript
15801580
/* recommended */
@@ -1610,9 +1610,9 @@ ou *Minificação e Anotação*
16101610
16111611
### Exception Catchers
16121612
1613-
- Create a factory that exposes an interface to catch and gracefully handle exceptions.
1613+
- Criar um factory que expôe uma interface para capturar excessões.
16141614
1615-
*Why?*: Provides a consistent way to catch exceptions that may be thrown in your code (e.g. during XHR calls or promise failures).
1615+
*Por que?*: Provides a consistent way to catch exceptions that may be thrown in your code (e.g. during XHR calls or promise failures).
16161616
16171617
Note: The exception catcher is good for catching and reacting to specific exceptions from calls that you know may throw one. For example, when making an XHR call to retrieve data from a remote web service and you want to catch any exceptions from that service and react uniquely.
16181618

i18n/it-IT.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,20 @@ Nonostante questa guida spieghi i *cosa*, *come* e *perché*, trovo che sia di a
370370

371371
Nota: Quando di creano watch in un controller usando `controller as`, puoi fare il watch del membro `vm.*` usando la seguente sintassi. (Crea watch con cautela poiché aggiungono carico al ciclo di digest.)
372372

373+
```html
374+
<input ng-model="vm.title"/>
375+
```
376+
373377
```javascript
374-
$scope.$watch('vm.title', function(current, original) {
375-
$log.info('vm.title was %s', original);
376-
$log.info('vm.title is now %s', current);
377-
});
378+
function SomeController($scope, $log) {
379+
var vm = this;
380+
vm.title = 'Some Title';
381+
382+
$scope.$watch('vm.title', function(current, original) {
383+
$log.info('vm.title was %s', original);
384+
$log.info('vm.title is now %s', current);
385+
});
386+
}
378387
```
379388

380389
### Membri che possono fare il bind in cima
@@ -553,31 +562,49 @@ Nonostante questa guida spieghi i *cosa*, *come* e *perché*, trovo che sia di a
553562
*Perché?*: Rimuove dipendenze e nasconde dettagli di implementazione dal controller.
554563
555564
```javascript
565+
556566
/* evitare */
557-
function Order($http, $q) {
567+
function Order($http, $q, config, userInfo) {
558568
var vm = this;
559569
vm.checkCredit = checkCredit;
570+
vm.isCreditOk;
560571
vm.total = 0;
561572

562-
function checkCredit() {
563-
var orderTotal = vm.total;
564-
return $http.get('api/creditcheck').then(function(data) {
565-
var remaining = data.remaining;
566-
return $q.when(!!(remaining > orderTotal));
567-
});
573+
function checkCredit() {
574+
var settings = {};
575+
// Prendi la URL di base per il servizio del credito
576+
// Setta le intestazioni necessarie per il servizio del credito
577+
// Prepara le URL della query string o i data object con i dati richiesti
578+
// Aggiungi le informazioni sull'identificazione dell'utente così il servizio prende i dati sul limite del credito corretto
579+
// Usare JSONP per questo browser se CORS non è supportato
580+
return $http.get(settings)
581+
.then(function(data) {
582+
// Unpack JSON data in the response object
583+
// to find maxRemainingAmount
584+
vm.isCreditOk = vm.total <= maxRemainingAmount
585+
})
586+
.catch(function(error) {
587+
// Errore dell'interprete
588+
// Affronta timeout? nuovo tentativo? provare servizi alternativi?
589+
// Rilancia con l'errore appropriato per essere letto dall'utente
590+
});
568591
};
569592
}
570593
```
571594
572595
```javascript
596+
573597
/* consigliato */
574598
function Order(creditService) {
575599
var vm = this;
576600
vm.checkCredit = checkCredit;
601+
vm.isCreditOk;
577602
vm.total = 0;
578603

579604
function checkCredit() {
580-
return creditService.check();
605+
return creditService.isOrderTotalOk(vm.total)
606+
.then(function(isOk) { vm.isCreditOk = isOk; })
607+
.catch(showServiceError);
581608
};
582609
}
583610
```
@@ -2506,7 +2533,7 @@ Usa file template o snippet che ti aiutino a seguire stili e schemi consistentem
25062533
25072534
- Snippet di AngularJS che seguono questi stili e linee guida.
25082535
2509-
- Scarica gli [snippet di Angular per Sublime](assets/sublime-angular-snippets.zip)
2536+
- Scarica gli [snippet di Angular per Sublime](assets/sublime-angular-snippets.zip?raw=true)
25102537
- Mettili nella tua cartella Packages
25112538
- Riavvia Sublime
25122539
- In un file JavaScript digita questi comandi seguiti da `TAB`
@@ -2532,7 +2559,7 @@ Usa file template o snippet che ti aiutino a seguire stili e schemi consistentem
25322559
25332560
- Snippet di Angular JS e file di template che seguono queste linee guida. Le puoi importare dentro i tuoi settaggi di WebStorm:
25342561
2535-
- Scarica i [file dei template e gli snippet diAngularJS per WebStorm](assets/webstorm-angular-file-template.settings.jar)
2562+
- Scarica i [file dei template e gli snippet diAngularJS per WebStorm](assets/webstorm-angular-file-template.settings.jar?raw=true)
25362563
- Apri WebStorm e vai al menù `File`
25372564
- Scegli la voce di menù `Import Settings`
25382565
- Seleziona il file e clicca `OK`

i18n/mk-MK.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
/* избегнувајте */
6969
angular
7070
.module('app', ['ngRoute'])
71-
.controller('someController' , someController)
72-
.factory('someFactory' , someFactory);
71+
.controller('someController', someController)
72+
.factory('someFactory', someFactory);
7373

7474
function SomeController() { }
7575

@@ -92,7 +92,7 @@
9292
// someController.js
9393
angular
9494
.module('app')
95-
.controller('SomeController' , SomeController);
95+
.controller('SomeController', SomeController);
9696

9797
function SomeController() { }
9898
```
@@ -103,7 +103,7 @@
103103
// someFactory.js
104104
angular
105105
.module('app')
106-
.factory('someFactory' , someFactory);
106+
.factory('someFactory', someFactory);
107107

108108
function someFactory() { }
109109
```
@@ -221,7 +221,7 @@
221221
```javascript
222222
/* избегнувајте */
223223
var app = angular.module('app');
224-
app.controller('SomeController' , SomeController);
224+
app.controller('SomeController', SomeController);
225225

226226
function SomeController() { }
227227
```
@@ -230,7 +230,7 @@
230230
/* препорачано */
231231
angular
232232
.module('app')
233-
.controller('SomeController' , SomeController);
233+
.controller('SomeController', SomeController);
234234

235235
function SomeController() { }
236236
```
@@ -533,7 +533,7 @@
533533
```
534534
535535
### Одлагање Логика во Контролерот
536-
###### [Style [Y035](#style-Y036)]
536+
###### [Style [Y035](#style-Y035)]
537537
- Одлагајте логика на во контролерот со делегирање до сервиси и фабрики.
538538
539539
*Зошто?*: Логиката може да биде повторно искористена кога е во сервис, од повеќе контролери и изложена преку функција.
@@ -544,18 +544,31 @@
544544
545545
```javascript
546546
/* избегнувајте */
547-
function Order($http, $q) {
547+
function Order($http, $q, config, userInfo) {
548548
var vm = this;
549549
vm.checkCredit = checkCredit;
550+
vm.isCreditOk;
550551
vm.total = 0;
551552

552-
function checkCredit() {
553-
var orderTotal = vm.total;
554-
return $http.get('api/creditcheck').then(function(data) {
555-
var remaining = data.remaining;
556-
return $q.when(!!(remaining > orderTotal));
557-
});
558-
};
553+
function checkCredit() {
554+
var settings = {};
555+
// Земете го URL-то на сервисот за кредит од config датотеката
556+
// Поставете ги потребните заглавија
557+
// Спремете го потребното URL барање или потребниот податочен објект за побарување на податоците
558+
// Додадете инфо за идентификација на корисникот за сервисот да добие точниот лимит на кредитот за овој корисник
559+
// Употребете JSONP за овој пребарувач доколку не подржува CORS
560+
return $http.get(settings)
561+
.then(function(data) {
562+
// Отпакувајте го JSON податокот во одговорот
563+
// за да го најдете maxRemainingAmount
564+
vm.isCreditOk = vm.total <= maxRemainingAmount
565+
})
566+
.catch(function(error) {
567+
// Интерпретирајте ја грешката
568+
// Спремете се со истекување на време? пробување пак? друг сервис?
569+
// Повторно одбиете за корисникот да ја забележи соодветната порака
570+
});
571+
};
559572
}
560573
```
561574
@@ -564,10 +577,14 @@
564577
function Order(creditService) {
565578
var vm = this;
566579
vm.checkCredit = checkCredit;
580+
vm.isCreditOk;
567581
vm.total = 0;
568582

569583
function checkCredit() {
570-
return creditService.check();
584+
return creditService.isOrderTotalOk(vm.total)
585+
.then(function(isOk) { vm.isCreditOk = isOk; })
586+
.catch(showServiceError);
587+
};
571588
};
572589
}
573590
```
@@ -2167,11 +2184,11 @@
21672184
//TODO
21682185
});
21692186

2170-
it('should have 10 Avengers', function() {}
2187+
it('should have 10 Avengers', function() {
21712188
//TODO (mock data?)
21722189
});
21732190

2174-
it('should return Avengers via XHR', function() {}
2191+
it('should return Avengers via XHR', function() {
21752192
//TODO ($httpBackend?)
21762193
});
21772194

@@ -2422,7 +2439,7 @@
24222439
###### [Style [Y250](#style-Y250)]
24232440
- AngularJS кратки кодови кои ги следат овие водичи и стилови на код.
24242441
2425-
- Симнете ги [Sublime Angular кратки кодови](assets/sublime-angular-snippets.zip)
2442+
- Симнете ги [Sublime Angular кратки кодови](assets/sublime-angular-snippets.zip?raw=true)
24262443
- Поставете ги во вашата Packages папка
24272444
- Рестартирајте го Sublime
24282445
- Во JavaScript датотека напишете ја следната команда и потоа кликнете на `TAB`
@@ -2446,7 +2463,7 @@
24462463
###### [Style [Y252](#style-Y252)]
24472464
- AngularJS кратки кодови и датотечни шаблони кои ги следат овие стилови и водичи на код. Можете да ги внесете во вашите WebStorm подесувања:
24482465
2449-
- Симнете ги [WebStorm AngularJS датотечни шаблони и кратки кодови](assets/webstorm-angular-file-template.settings.jar)
2466+
- Симнете ги [WebStorm AngularJS датотечни шаблони и кратки кодови](assets/webstorm-angular-file-template.settings.jar?raw=true)
24502467
- Отворете го WebStorm и одберете го `File` менито
24512468
- Одберете го `Import Settings`
24522469
- Одберете ја датотеката и кликнете `OK`

0 commit comments

Comments
 (0)