Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
42
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
code.vt.edu will be down for maintenance from 0530-0630 EDT Wednesday, March 26th
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
8268845c
Commit
8268845c
authored
8 years ago
by
William Welling
Browse files
Options
Downloads
Patches
Plain Diff
Use lifecycle hooks to unsubscribe
parent
1a8aabc9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/app.component.ts
+12
-4
12 additions, 4 deletions
src/app/app.component.ts
with
12 additions
and
4 deletions
src/app/app.component.ts
+
12
−
4
View file @
8268845c
import
{
Component
,
ChangeDetectionStrategy
,
OnInit
,
ViewEncapsulation
}
from
'
@angular/core
'
;
import
{
Component
,
ChangeDetectionStrategy
,
OnDestroy
,
OnInit
,
ViewEncapsulation
}
from
'
@angular/core
'
;
import
{
TranslateService
}
from
'
ng2-translate
'
;
...
...
@@ -9,7 +9,7 @@ import { TranslateService } from 'ng2-translate';
templateUrl
:
'
./app.component.html
'
,
styleUrls
:
[
'
./app.component.scss
'
]
})
export
class
AppComponent
implements
OnInit
{
export
class
AppComponent
implements
OnDestroy
,
OnInit
{
example
:
string
;
...
...
@@ -18,6 +18,8 @@ export class AppComponent implements OnInit {
recipient
:
'
World
'
}
private
registerSubscription
:
any
;
constructor
(
public
translate
:
TranslateService
)
{
// this language will be used as a fallback when a translation isn't found in the current language
translate
.
setDefaultLang
(
'
en
'
);
...
...
@@ -26,9 +28,15 @@ export class AppComponent implements OnInit {
}
ngOnInit
()
{
this
.
translate
.
get
(
'
example.with.data
'
,
{
greeting
:
'
Hello
'
,
recipient
:
'
DSpace
'
}).
subscribe
((
res
:
string
)
=>
{
this
.
example
=
res
;
this
.
registerSubscription
=
this
.
translate
.
get
(
'
example.with.data
'
,
{
greeting
:
'
Hello
'
,
recipient
:
'
DSpace
'
}).
subscribe
((
translation
:
string
)
=>
{
this
.
example
=
translation
;
});
}
ngOnDestroy
()
{
if
(
this
.
registerSubscription
)
{
this
.
registerSubscription
.
unsubscribe
();
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment