angularjs-controlleras

Why can't I overwrite the value of a variable like this?

こ雲淡風輕ζ 提交于 2019-11-28 13:32:49
I'm trying to figure out why I'm having trouble overwriting a value passed to an angularJS directive via an isolate scope ( @ ). I try to overwrite the value of vm.index with the following: vm.index = parseInt(vm.index, 10) However, it doesn't work for some reason. If I change it to: vm.newIndex = parseInt(vm.index, 10) It works. Also, assigning the value on the $scope works. Why doesn't the first method work? I've created this example plunker for reference. As you used @ here which need value from an attribute with {{}} interpolation directive. And seems like directive is getting loaded first

JavaScript | Angular | Controller As Syntax: Cannot Use `this`

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:34:04
问题 Cannot Use ControllerAs this Can anyone explain the following scenario to me, please? Works ng-controller="Parent as thus" Breaks ng-controller="Parent as this" That single letter which makes it a keyword -- which I want -- wrecks the forest. Why is this? P.S. I'm aware of the vm convention, but I find it disturbs portability of controllers/viewmodels. 回答1: The problem is certainly not that this is a reserved word in JavaScript. There is no rule in the controller as syntax that says you would

Why can't I overwrite the value of a variable like this?

烈酒焚心 提交于 2019-11-27 19:29:24
问题 I'm trying to figure out why I'm having trouble overwriting a value passed to an angularJS directive via an isolate scope ( @ ). I try to overwrite the value of vm.index with the following: vm.index = parseInt(vm.index, 10) However, it doesn't work for some reason. If I change it to: vm.newIndex = parseInt(vm.index, 10) It works. Also, assigning the value on the $scope works. Why doesn't the first method work? I've created this example plunker for reference. 回答1: As you used @ here which need

How to pass data between sibling components without using $scope?

大城市里の小女人 提交于 2019-11-26 21:29:38
I am making a component that contains 3 child components in this way: <header-component> <side-component> <main-component> The main component contains list of heroes. The header component contains two buttons that are suppose to switch the view on the main component to list or grid view. The problem I have now is passing data from the header-component to the main component. So when I click grid button the view on the main content should change to grid view , same for the row view. How can the data be passed between child components in angular 1.5 ? dfsq Component approach I would suggest you

How to pass data between sibling components without using $scope?

邮差的信 提交于 2019-11-26 06:17:26
问题 I am making a component that contains 3 child components in this way: <header-component> <side-component> <main-component> The main component contains list of heroes. The header component contains two buttons that are suppose to switch the view on the main component to list or grid view. The problem I have now is passing data from the header-component to the main component. So when I click grid button the view on the main content should change to grid view , same for the row view. How can the