Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
hi below is the code that i have written, it's tutorial example from the internet (https://cdnjs.com/libraries/backbone.js/tutorials/what-is-a-view/)
<<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js" type="text/javascript"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js" type="text/javascript"></script>
</head>
<body>
<div id ="search_container">a</div>
<script type="text/template" id="search_template">
<label>Search</label>
<input type="text" id='search_input' />
<input type="button" id="search_button" value="search" />
</script>
<script type="text/javascript">
SearchView = Backbone.View.Extend({
initialize: function(){
this.render();
},
render: function(){
// Compile the template using underscore
var template = _.template($('search_template').html(),{});
// Load the compiled HTML into the Backbone "el"
this.$el.html(template);
},
events:{
"click input[type=button]": "doSearch"
},
doSearch: function(){
alert("search for " + $('#search_input').val());
}
});
var search_view = new SearchView({el: $('#search_container')});
</script>
</body>
</html>
I do not understand what i am doing wrong, Please guide me. thanks
nikoshr is right you have to use extend with lowercase and form making work the example you must change
var template = _.template($('search_template').html(),{});
to
var template = _.template($('#search_template').html(),{});
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
just try the following code and getting the error
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Routing Intro</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-resource.min.js"></script>
<script scr="example.js"></script>
</head>
<body ng-app="mainApp">
<div ng-view></div>
</body>
</html>
here is my example.js file
var application = angular.module ('mainApp', ['ngRoute']);
application.config (function ($routeProvider){
$routeProvider
.when('/', {
template : 'Welcome User!'
})
.when('/anotherPage',{
tempalte : 'Welcome to Another page'
})
otherwise ({
redirectTo : '/'
});
});
I am getting the following error
angular.js:4458 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=mainApp&p1=Error%3A…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463)
Angular router is not a part of core angular module. You need to include it's javascript file:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.min.js"></script>
This question already has answers here:
Underscore template throwing variable not defined error
(2 answers)
Closed 6 years ago.
Just playing with Backbone and Underscore, I ran across this error:
ReferenceError: can't find variable: search_label
Here's the whole code:
<!DOCTYPE html>
<head>
<title>Router Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/template" id="search_template">
<label><%= search_label %></label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</script>
<div id="search_container"></div>
<script type="text/javascript">
var SearchView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
var variables = {search_label: "My Search"};
var my_template = _.template($('#search_template').html(), variables);
this.$el.html(my_template);
}
});
var search_view = new SearchView({el: $('#search_container')});
</script>
</body>
</html>
Why is it complaining about the search_label and how can it be resolved?
Thank you.
The _.template() method has a breaking change in recent versions (1.7.0 onward),
Now the second argument of _.template is a settings object, not the data for template. It returns a template function that accepts the data and returns the actual HTML.
So you should do
var my_template = _.template($('#search_template').html());
var html = my_template(variables);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am facing issue to print text using angualrjs $scope and $rootscope.
Please find the code below and let me know where i did mistake.
<body ng-app="x">
<div ng-controller="ctrl1">
Hello {{name2}}
</div>
<div ng-controller="ctrl2">
Hi {{name1}} How {{name3}}
</div>
<script>
var app= angulr.module("x",[]);
app.controller("ctrl1" ,['$scope', '$rootScope',function($scope, $rootscope){
$scope.name2 = "Sir";
$rootscope.name3 = "are you!";
}]);
app.controller("ctrl2", function($scope){
$scope.name1 = "madam";
});
</script>
</body>
Please run the following code. Problem solved. You spelled angular incorrectly and you dont need to put scope and rootScope in bracket in ctrl1 in controller. Also it is rootScope and not rootscope (check the capital S)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<body ng-app="x">
<div ng-controller="ctrl1">
Hello {{name2}}
</div>
<div ng-controller="ctrl2">
Hi {{name1}} How {{name3}}
</div>
<script>
var app= angular.module("x",[]);
app.controller("ctrl1" ,function($scope, $rootScope){
$scope.name2 = "Sir";
$rootScope.name3 = "are you!";
});
app.controller("ctrl2", function($scope){
$scope.name1 = "madam";
});
</script>
</body>
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="x">
<div ng-controller="ctrl1">
Hello {{name2}}
</div>
<div ng-controller="ctrl2">
Hi {{name1}} How {{name3}}
</div>
<script>
var app = angular.module('x', []);
app.controller("ctrl1" ,['$scope', '$rootScope',function($scope, $rootscope){
$scope.name2 = "Sir";
$rootscope.name3 = "are you!";
}]);
app.controller("ctrl2", function($scope){
$scope.name1 = "madam";
});
</script>
</body>
</html>
I am getting an strange error while using ngTagInput library:
Error: type property can't be changed.
Here is the screenshot of that error - Error Screenshot.
HTML Code -
<html ng-app="project">
<head>
<link href="/css/ng-tags-input.bootstrap.min.css" rel="stylesheet"/>
<link href="/css/ng-tags-input.min.css" rel="stylesheet" />
<script type="text/javascript" src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'></script>
<script type="text/javascript" src="/assets/bootstrap-3.2.0-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src='/js/angular.min.js'></script>
<script src="/js/ng-tags-input.min.js"></script>
<script src="/js/app.js"></script>
</head>
<body>
<form ng-controller="MainCtrl" role="form">
<div class="col-md-12 topM10px">
<tags-input ng-model="formInfo.tags" placeholder="Add a keyword"></tags-input>
</div>
<div class="col-md-12 topM10px">
<div ng-click="submitidea()" class="col-md-3 submitbtn">Submit</div>
</div>
</form>
</body>
</html>
Controller code (app.js)-
var app = angular.module('project', ['ngTagsInput']);
app.controller('MainCtrl', function($scope, $http) {
$scope.formInfo = {};
$scope.tags = [
{ text: 'Tag1' },
{ text: 'Tag2' },
{ text: 'Tag3' }
];
$scope.submitidea = function(){
console.log($scope.formInfo);
}
});
Please someone help. Thanks in advance
You appear to have a conflict between one of more of your libraries. This can probably be resolved by isolating which library is causing the issue (when commented out, the error goes away), and then trying different versions of that library and/or Angular.
I did a fiddle that uses the same version of Bootstrap and jQuery that you are, but is using Angular 1.4.8 instead of 1.5, so I believe the conflict is between jQuery 1.8.1 and Angular v1.5.0-rc.0 since the fiddle works without any errors. Recommend dropping your Angular version down to 1.4.8 and see if that resolves the issue.
Add library angular first
For example:
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Guys please check my below code, Why its not working..
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body ng-app>
<h1 ng-controller="HWCtrl">{{helloMessage}}</h1>
<srcipt src="angular.js"></srcipt>
<script type="text/javascript">
function HWCtrl($scope) {
$scope.helloMessage = 'Hello World';
}
</script>
</body>
I created HWCtrl function for a ng-controller.. Thanks in advance
You misspelled script:
<srcipt src="angular.js"></srcipt>
^-- here ^-- and here