Answer the question
In order to leave comments, you need to log in
How to properly work with a component in Angular 1.5?
I am making a component.
app.component('changer', {
templateUrl: 'changer.html',
controller: changerController,
bindings: {
sostpr: '=',
}
});
<changer id="rrr" sostpr="5"></changer>
<div class="bgnk" ng-class="{'prvkl':sostpr==1,'prvikl':sostpr!=1}" value="1" ng-click="chgelem()" ng-swipe-left="chgelem(0)" ng-swipe-right="chgelem(1)" ><div class="krug" ></div></div>
function changerController($scope, $element, $attrs) {
var ctrl = this;
$scope.chgelem=function(sost){
alert(ctrl.sostpr)
if (sost==undefined){
if ($scope.sostpr==1){
$scope.value=0;
}else{
$scope.value=1;
}
}else{
$scope.value=sost;
}
$scope.sostpr=$scope.value
ctrl.sostpr=2;
}
}
Answer the question
In order to leave comments, you need to log in
1) The external controller cannot "look" into the component scope, if the component must report some changes to its parent, this is done through the '&' binding
https://docs.angularjs.org/guide/component
2) the content of the component controller is available via $ctrl, you don’t need to throw them into the scope with your hands
https://github.com/rwwagner90/angular-styleguide-es6
The event can also be hung in the template, if you suddenly hang the event in the constructor on the element, do not forget to unsubscribe from the event in the destructor
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question