I want to be able to reuse my ui-router-wired controllers. They currently receive parameters from ui-router resolve to render their templates. Can I reuse those controllers without ui-router?
For example, I do this with ui-router:
.controller('DetailController', function ($scope, detailData) {
$scope.controllerDetail = detailData + "is awesome!";
})
.config(function ($stateprovider) {
$stateprovider.state('detailState', {
resolve: {
detailData: function () { return "John Doe"; }
},
template: '<p>{{ controllerDetail }}</p>',
controller: 'DetailController'
}
}
Now, I want to use the same controller to render a fixed sub-panel elsewhere. For example:
<master ng-init='childData="Jane Smith"'>
<detail ng-controller='DetailController' ng-controller-params="{ detailData : childData">
<p>{{ controllerDetail }}</p>
</detail>
</master>
Of course, in practice, there are actually template files, and some functionality in the controller worth de-duplicating. Also, the resolve data in the first example and init data in the second example both arrive over the wire, but in the second example it arrives as a child object of a larger request rather than an individually-navigated item. Also, I assign my controllers in directives rather via HTML attributes.
namevariable is passed