I'm trying to use requirejs to load knockoutjs in following way:
<script type="text/javascript">
require(['scripts/knockout-2.2.1.debug'], function() {
var someModel = {
firstname: ko.observable('asd')
};
ko.applyBindings(someModel);
});
</script>
Where require.js is loaded using a Script Tag on top. When this code executes, I get a ko is not defined error. What's the correct way to do similar?
require(['scripts/knockout-2.2.1.debug'], function(ko) {
I'm not sure but seeing the example on requirejs, I guess these are loaded inside the scope of that callback function. So, unless you accept that in your function, you can't use it.
Yes, you are right (at least, seeing their exmaple). if you include 4 libraries, you need to accept 4 parameters. for example, if you loaded jquery and knockout, you can write it as follows:
require(['scripts/jquery.js', 'scripts/knockout-2.2.1.debug'], function($, ko) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With