Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. var app = angular.module("test", []);
  2. app.component("test", {
  3. bindings: {
  4. "contactId": "<"
  5. },
  6. controllerAs: "model",
  7. controller: () => {
  8. //output: 'contact id from controller: undefined'
  9. console.log(`contact id from controller: ${this.contactId}`);
  10. },
  11. template: "<div>Contact id from view: {{model.contactId}}</div>"
  12. });
  13.  
  14. <test contact-id="8"></test>
  15.  
  16. app.component("test", {
  17. bindings: {
  18. "myContactId": "<"
  19. }
  20. }
  21.  
  22. <test my-contact-id="8"></test>
  23.  
  24. var app = angular.module("test", []);
  25. app.component("test", {
  26. bindings: {
  27. "contactId": "<"
  28. },
  29. controllerAs: "model",
  30. controller: ($scope) => {
  31. var model = $scope.model;
  32. alert(`contact id from controller: ${model.contactId}`);
  33. },
  34. template: "<div>Contact id from view: {{model.contactId}}</div>"
  35. });
  36.  
  37. controller: function() {
  38. alert('contact id from controller: ' + this.contactId);
  39. }
  40.  
  41. app.component("test", {
  42. bindings: {
  43. "myContactId": "<"
  44. },
  45. controller:function(){
  46. var self=this;
  47. this.$onInit=function(){
  48. // do all your initializations here.
  49. // create a local scope object for this component only. always update that scope with bindings. and use that in views also.
  50.  
  51. self.myScopeObject=self.myContactId
  52. }
  53. },
  54. template:'<p>{{$ctrl.myScopeObject}}</p>'
  55. }
  56.  
  57. <test my-contact-id="8"></test>
  58.  
  59. bindings:{
  60. value:'@',
  61. object:'<', // also known as one-way
  62. twoWay:'='
  63. }
  64.  
  65. $scope.$ctrl.contactId
  66.  
  67. /*bindings: {
  68. modalInstance: '<',
  69. resolve: '<'
  70. },*/
  71. scope: {
  72. modalInstance: '<',
  73. resolve: '<'
  74. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement