I am trying to run a very simple an basic sample of a backbone model that is found on a tutorial for learning the library.
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.string/2.3.3/underscore.string.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script>
User = Backbone.Model.extend({
initialize: function() {
alert("Backbone model initialized");
}
});
var user = new User;
</script>
But on the console there are 2 errors :
Uncaught TypeError: Object # has no method 'each' on the backbone-min file
Uncaught ReferenceError: Backbone is not defined
And is not working.
Would yo please help me understand what am I doing wrong?
You're not loading the full underscore library. Replace the second script tag with the following:
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
Related
I am a beginner with AngularJs and I am trying to use controller while creating a simple application. However I am getting an Error and I can't quite figure it out
Error: ng:areq Bad Argument. Argument 'languages' is not a function, got undefined
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<title>Angular JS | Controllers</title>
<script type="text/javascript" src="../resources/js/angular.min.js"></script>
<script>
(function(angular){
var myApp = angular.module('myApp', []);
myApp.controller = ('languages', function($scope){
$scope.myFavLanguage = 'None';
});
})(window.angular);
</script>
</head>
<body >
<div ng-controller="languages">
Select your favourite langauge:
<button>ReactJS</button>
<button>PHP</button>
<button>JavaScript</button>
<button>C++</button>
<p>Your favourite language is {{myFavLanguage}}</p>
</div>
</body>
</html>
I have searched over the internet and gone through a few questions on stackoverflow and could'nt get any of them to solve my problem.
These are the ones that I have visited along with a few others. Kindly visit these before marking it as duplicate because it isn't:
Angularjs bad argument ng:areq error
Angularjs: Error: [ng:areq] Argument 'HomeController' is not a function, got undefined
Argument ... is not a function, got undefined
Thanks for any help
To define a controller, use the controller() method.
myApp.controller = ('languages', function($scope){
^
Remove the = from this.
myApp.controller('languages', function($scope) {
Check Docs for more information.
I'll suggest you to use min-safe syntax.
myApp.controller('languages', [$scope, function ('$scope') {
}]);
I have been trying to implement external templates, but to no avail.
This is the full error:
Uncaught TypeError: Invalid template! Template should be a "string" but "undefined" was given as the first argument for mustache#render(template, view, partials)
I am using browserify-shim for some other dependencies, but they work perfectly, and I am not getting errors (from that task) from the terminal. It's just the external template loading which is giving me problems.
function templateLoader(e) {
var doc = document,
event = EventUtility.getEvent(e),
target = EventUtility.getTarget(event);
$("body").load("templates/index.html #overlay", function() {
var temp1 = $('#overlay').html();
var output = Mustache.render(temp1);
$("body").html(output);
});
}
var flimFlam = document.getElementById('Container');
EventUtility.addHandler(flimFlam, 'click', templateLoader);
Thanks so much in advance!
Try to put everything in
$(document).ready(function(){
});
I had the same error and it worked for me.
because your Mustache template is probably nested in the rendering template. separate them and this error should go away.
I tried to learn backbone with marionette .I started learning from this book and make simple program
marionette-gentle-introduction-sample.pdf
I am getting this error
this._initializeRegions is not a function
here is my codepen
http://codepen.io/anon/pen/epvoVm
var app =Marionette.Application();
app.staticView=Marionette.ItemView.extend({
e1:"#main-region",
template: "#static-template"
})
app.on('start',function(){
console.log('---')
var staticView = new ContactManager.staticView();
staticView.render();
})
app.start()
I didn't get any console message but I am getting error on console
Uncaught TypeError: this._initializeRegions is not a function
Morning
I'm not to sure on marionette but I believe you need to call a new instance of the application. I tested and it seems to work.
var app = new Marionette.Application();
I am getting this error in the console.
Uncaught TypeError: Object [object Object] has no method 'bxSlider'
I have no idea why this is happening though. I had all of this working perfectly but then when i put it into a NetSuite store it stops working.
This is running jQuery in NoConflict i don't need to change all of the "$" to jQuery in the plugin do I?
This is where i am calling jQuery, the Plugin and the script for it.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">jQuery.noConflict();</script>
<script type="text/javascript" src="/site/js/modernizr.custom.93936.js"></script>
<script src="/site/js/jquery.bxslider.js"></script>
<script>
jQuery(document).ready(function(){
jQuery('.bxslider').bxSlider({
auto: true,
controls: false
});
});
</script>
And this is the entire console error.
Uncaught TypeError: Object [object Object] has no method 'bxSlider' dtv:57
(anonymous function) dtv:57
n jquery.min.js:2
o.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B
What could be the cause here i am so lost have been trying every little thing that i know and nothing is making it work.
May be it because of jquery conflict.
Please recheck your code, may be you added jquery twice. Or change the latest jquery.
It may be because of a jquery conflict and it is good advice to check your code (for instace using the console or developer tools of your favorite browser) for jquery being loaded twice.
You should also check to see if the js file for bxSlider is being loaded in the console as there may be a typo in the path to it.
One other reason that could cause this is the order in which scripts are loaded. If bxSlider is loaded before jquery it will give this error. You can check this by looking at the source code for the page or by looking at Network tab in developer tools.
This is also a problem if you have not raked assets.
rake assets:clean && rake assets:precompile
I found that putting
jQuery(document).ready(function(){
jQuery('.bxslider').bxSlider({
auto: true,
controls: false
});
})
in a file (settings.js, was also more efficient in detecting where the error was and apparently more likeable by WordPress.
I got this when omitting the braces () when declaring the function.
Incorrect code:
var calcResults = (function () {
.....
});
Correct code:
var calcResults = (function () {
.....
})(); //<<-- these () were missing
I'm learning backbone.js and already have a problem.
I'm loading my scripts with LABjs like this:
$LAB.setOptions({BasePath : path})
.script('libs/underscore.js?v=1.3.3')
.script('libs/backbone.js?v=0.9.2')
.script('libs/jquery.js?v=1.7')
.script('libs/bootstrap.min.js?v=2.0.2').wait()
.script('test.js');
In my test.js I have this (from backbonetutorials.com):
(function($){
SearchView = Backbone.View.extend({
initialize: function(){
alert("Alerts suck.");
}
});
var search_view = new SearchView;
})(jQuery);
As you see this should give me an alert with text "Alerst suck.".
Instead it throws an error on my firebug console - i is not a function (34 line of backbone.js).
If I try to initialize view like this var search_view = new SearchView({el: $('#some_dom_element')}); it gives me another error - invalid 'instanceof' operand i (34 line of backbone.js file).
jQuery object $ is defined.
I can initialize Backbone.js models without any problems. Just view throws those errors. What I am missing?
It seems that order in which scripts are loaded matters. I've loaded jQuery first now and it started to work. I've also tested it with non minified version of backbone.js and the error was more verbose $ is not a function. So again - loading jQuery before backbone.js fixed it.
EDIT: When loading jQuery after backbone.js when I do console.log($) right before view initialization it shows tha $ is a function. Why backbone.js fails to work then? Can someone explain this?