I'm trying my hand in writing custom directives and ran into a problem.
I'm implementing a ANCHOR BUTTON directive, through which I can assign values for ICON, TEXT and STATE(UI-SREF)
HTML template
<v-anc-btn-get state="profile({ id: editor.profileId })" text="Get Profile" icon="fa-book">
</v-anc-btn-get>
DIRECTIVE
function anchorButtonDirective() {
var directive =
{
restrict: "E",
template: "<a class='btn btn-info' ui-sref='ctrl.go()'><i class='fa {{ctrl.icon}}'></i> {{ctrl.text}}</button>",
scope:
{
icon: "@",
text: "@",
state: "&"
},
controller: function ($state, $stateParams) {
var ctrl = this;
ctrl.go = function () {
return ctrl.state;
}
},
controllerAs: "ctrl",
bindToController: true
};
return directive;
}
Now, the directive throws an error like Could not resolve 'go' from state 'xxx.xx'
What am I doing wrong here?
How do I fix it?? so that I can navigate to the state which I have specified in the directive?
Thanks for the help
EDIT 1
Edited as per @DanielC's comments.