Hi all ,
I’m using Aurelia with enhance mode (with existing asp.net mvc site)
Some of Aurelia features aren’t working : Inject , autoinject , @bindable
Is there a reason may cause this ? Is there a best practice to use aurelia in an existing site.
Here is the code I’m using to initialize Aurelia
<script type="text/javascript">
window.BaseWebAPIUrl = '@(ViewBag.BaseWebAPIUrl)';
function applyAurelia() {
requirejs(['aurelia-bootstrapper', 'aurelia-event-aggregator'], function (bootstrapper, aggregator) {
bootstrapper.bootstrap(function (aurelia) {
requirejs(['modules/violation/violationSummaries'], function (r) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.feature("resources")
.developmentLogging();
var vm = new r.ViolationSummaries;
aurelia.start().then(function () {
aurelia.enhance(vm, document.body);
});
});
});
});
}
</script>
If you are wondering why your root view model (created by var vm = new r.ViolationSummaries;) doesn’t have the dependencies declared with @inject or @autoinject. Then change that to this:
var vm = new aurelia.container.get(r.ViolationSummaries);
About a 1 year back I created a pivot table view in existing MVC 5 project.
Didn’t use enhance, want to share how I did it back then, but not saying this is “best practice”.
The project has a tree view and when the user selects an item, it calls a method in the app.ts of the Aurelia app. This updates the pivot table view when this view mode is activated.
function selectProjectItem(selectedId) {
require(['app'], function (module) {
var App = module.App;
var appRoot = $("#aureliaPivot")[0];
var container = appRoot.aurelia.container;
var app = container.get(App);
app.selectProjectItem(selectedId);
});
}