I am learning a fashionable way to write controllers by avoiding direct access to $ scope. There is such a controller
(function (angular) { 'use strict'; angular .module('myApp', [ 'ngAnimate', 'vAccordion' ]) .controller('MainController', function ($scope) { $scope.panesA = [{ id: 'pane-1a', header: 'Pane 1', content: 'Curabitur et...', isExpanded: true }, { id: 'pane-2a', header: 'Pane 2', content: 'Lorem...' }, { id: 'pane-3a', header: 'Pane 3', content: 'Aliquam erat...' }]; $scope.expandCallback = function (index, id) { console.log('expand:', index, id); }; $scope.collapseCallback = function (index, id) { console.log('collapse:', index, id); }; $scope.$on('accordionA:onReady', function () { console.log('accordionA is ready!'); }); }); })(angular); I rewrite it like this:
(function (angular) { 'use strict'; angular .module('myApp', [ 'ngAnimate', 'vAccordion' ]) .controller('MainController', MainController); function MainController() { var vm = this; vm.panesA = [{ id: 'pane-1a', header: 'Pane 1', content: 'Curabitur et...', isExpanded: true }, { id: 'pane-2a', header: 'Pane 2', content: 'Lorem...' }, { id: 'pane-3a', header: 'Pane 3', content: 'Aliquam erat...' }]; vm.expandCallback = function (index, id) { console.log('expand:', index, id); }; vm.collapseCallback = function (index, id) { console.log('collapse:', index, id); }; vm.$on('accordionA:onReady', function () { console.log('accordionA is ready!'); }); }); })(angular); If you have a lot of experience, then laugh at your health). For me, both the reference to the material on the question and the rewritten controller will be valuable. Who does not understand what the problem is, here
vm. $ on ('accordionA: onReady', function () {
If you want to play, then here is http://codepen.io/LukaszWatroba/pen/MwdaLo I’ve cut off the controller and the view for a bit. I have as in question, and the example is completely on CodePen.
I understand that the $ on angular method is only in angular objects, and therefore is not called. Then how to do something like
var $jQueryObjectNow = $('#abcd').jQueryMethod(); or replace the design?
$scope.$on('accordionA:onReady', function () {
function MainController($scope) {- Grundy