问题描述:

Starting at a new job I have just inherited a previous developer's not-at-all-documented and weirdly-structured Ionic project. Long story short, it has come to my attention that a simple directive like this (generated using McFly Generator, although I have tried any number of ways of structuring and including the directive):

myDirective.js

'use strict';

/*eslint consistent-this:[2, "myDirectiveCtrl"] */

var directivename = 'myDirective';

module.exports = function(app) {

// controller

var controllerDeps = [];

var controller = function() {

var myDirectiveCtrl = this;

myDirectiveCtrl.directivename = directivename;

};

controller.$inject = controllerDeps;

/*eslint-disable consistent-this */

// directive

var directiveDeps = [];

var directive = function() {

return {

restrict: 'AE',

scope: {

title: '@' // '@' reads attribute value, '=' provides 2-way binding, '&" works with functions

},

controller: controller,

controllerAs: 'myDirectiveCtrl',

bindToController: true,

template: require('./myDirective.html'),

compile: function(tElement, tAttrs) {

return {

pre: function(scope, element, attrs) {

},

post: function(scope, element, attrs) {

}

};

}

};

};

directive.$inject = directiveDeps;

app.directive(directivename, directive);

};

相关阅读:
Top