angularjs - how to use angular 1 variables inside the angular 2 component -


login.js

var app= angular.module('login',[]);  app.controller('loginctrl', function($scope) {  $scope.sayhello="hello"+ $scope.username;  }).directive('logindir', function(){  return {   scope:{},   templateurl: 'logintpl.html',   controller: 'loginctrl' }; });  var adapter = new ng.upgrade.upgradeadapter();  appcomponent = ng.core   .component({     selector: 'login',     directives: [adapter.upgradeng1component('logindir')],     template: '<login-dir></login-dir>'     })   .class({     constructor: function() {}   });  app.directive('login', adapter.downgradeng2component(appcomponent)); document.addeventlistener('domcontentloaded', function() {   adapter.bootstrap(document.body, ['login']);   console.log(adapter); }); 

logintpl.html

<input type="name" ng-model="username"> 

how can use $scope.sayhello variable inside component.

eg: component template should be,template:'<login-dir></login-dir>{{sayhello}}

appcomponent = ng.core   .component({     selector: 'login',     directives: [adapter.upgradeng1component('logindir')],     template: '<login-dir></login-dir> {{sayhello}}'     })   .class({     constructor: function() {         this.sayhello = "hello world !!!";     }   }); 

explanation

in angular 2, there no model called $scope. replaced simple variables in class.

we can consider whole class controller in angular 1.x. can create variable this.variable_name in class. constructor function invoked first in component. so, can initialize our variable here.

so, $scope.variable_name in angular 1.x same (or to) this.variable_name in angular 2.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -