getting started with reactjs component is not working - reactjs

i am new to reactjs and facing problem at my first step.
please help me.
below is my code..
i have written same code in "custom.jsx" file but problem is the same(no output)
<!DOCTYPE html>
<html lang="en">
<head>
<title>react demo</title>
<link rel="stylesheet" type="text/css" href="common/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="common/css/style.css" />
</head>
<body>
<div id="root"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom-server.js"></script>
<script type="text/javascript" src="common/js/bootstrap.min.js"></script>
<script src="common/js/custom.jsx"></script>
<script type="text/jsx">
var button = React.createClass({
render: function(){
return (
<button>go</button>
)
}
});
React.render(<button />,document.getElementById("root"));
</script>
</body>
</html>

Change the name of variable it will work.
Reason is: name starts with small letters are treated as HTML elements, that's why all React components must start with a upper case letter, Check this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>react demo</title>
<link rel="stylesheet" type="text/css" href="common/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="common/css/style.css" />
</head>
<body>
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.23.1/babel.min.js"></script>
<script type="text/jsx">
var Button = React.createClass({
render: function(){
return (
<button>go</button>
)
}
});
ReactDOM.render(<Button/> ,document.getElementById("root"));
</script>
</body>
</html>

Related

Uncaught referenceError : Angular is not defined

I am seeing the error as shown in the image.
Error displayed in the console.
This is my App.js code:
var app = angular.module('PopupDemo',[]);
app.controller('PopupDemoCont',function($scope) {
});
This is my HTML code:
<html>
<head>
<title>SignUp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="signup.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="js/App.js"></script>
<script src="js/angular.min.js"></script>
<script src="js/ui-bootstrap-tpls-0.14.3.min.js"></script>
</head>
<body ng-app="PopupDemo">
<div data-toggle="validator" class="container-fluid" ng-controller="PopupDemoCont">
<h1><b>Sign Up</b></h1>
</br>
<form id="form" name="userForm" action="Registration.html">
</body>
</html>
Can anyone fix this?
Your app.js shoud be below angular reference
<script src="js/angular.min.js"></script>
<script src="js/App.js"></script>
Your references Order should be
<script src="js/angular.min.js"></script>
<script src="js/App.js"></script>

React component error

Hello guys for 2 days i am trying to call a react component from html and every time it throw me that error "Error: Cannot find react component MyReact"
so that is my html.I would be very grateful if someone help me
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/datepicker.css">
<link rel="stylesheet" href="css/angular-material.min.css">
<script src="react-15.3.0.js"></script>
<script src="react-dom-15.3.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>
</head>
<body ng-app="listOfDiaries" ng-controller="myCtrl as ctrl">
<react-component name="MyReact"></react-component>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc2/angular-material.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular-messages.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src = 'js/bootstrap.js'></script>
<script src="js/ngReact.js"></script>
<script type="text/babel" src="tutorial.js"></script>
<script src = 'config.js'></script>
<!--data-toggle="modal" data-target="#{{myprops.id}}"-->
</body>
</html>
that is tutorial file:
var MyReact = React.createClass({
render: function() {
console.log("qweqw");
return(
<div>
<h2>georgi</h2>
</div>
);
}
});
app.value('MyReact',MyReact);
and my config file:
var app = angular.module('listOfDiaries', ['react','ngMaterial','ngMessages']);
app.controller('myCtrl', ["$scope", "myFirstService", function ($scope, myFirstService) {
var self = this;
//and directive and so on..
I don't program Angular; but looking at the code in the app.directive statement; if that code is run immediately MyReact is not defined. Try switch the MyReact class and the app.directive block.

Display Hello, Angular! in Angular JS

I have written the following program to print Hello, Angular! but it does not work. Please guide.
<!DOCTYPE html>
<html ng-app="gemStore" ng-init="person={text:'Hello, Angular!'>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
<h1><div>
{{person.text}}
</div></h1>
</body>
</html>
You need a closing brace and quote for the ng-init
ng-init="person={text:'Hello, Angular!'}"
Replace :
ng-init="person={text:'Hello, Angular!'>
with:
ng-init="person={text:'Hello, Angular!'}">
You have typo mistake, replace your code with below.
<!DOCTYPE html>
<html ng-app="gemStore" ng-init="person={text:'Hello, Angular!'}>
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
<h1><div>
{{person.text}}
</div></h1>
</body>
</html>
You forgot the right bracet and the quote. See the example below.

Error: angular is undefined in app.js

I have the following simple html file
<!DOCTYPE html>
<html ng-app="store">
<head>
<title></title>
<link href="bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<script src="angular.min.js" type="text/javascript" ></script>
<script src="app.js"></script>
<p>{{Hello Angular!!}}</p>
</body>
</html>
and app.js file
'use strict';
var app = angular.module('store', []);
I'm getting error "angular is undefined" while running HTML file under webserver. Can anyone please suggest what I'm doing wrong!
Please check your reference file.
like.
<!DOCTYPE html>
<html ng-app="store">
<head>
<title></title>
<link href="bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<script src="https://code.angularjs.org/1.4.0-beta.5/angular.js"></script>
<script src="app.js"></script>
<p>{{Hello Angular!!}}</p>
</body>
</html>

Error when injecting angular-animate.js

I am receiving the following error when injecting angular-animate.js:
Unknown provider: $animateProvider from ngAnimate
Here is my app.js:
var MyApp = angular.module("MyApp", ["ui.bootstrap", "ngAnimate"])
Here is head of index.html:
<html lang="en" ng-app="MyApp">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="app.js"></script>
<script type="text/javascript" src="angular-animate.js"></script>
<script type="text/javascript" src="ui-bootstrap-tpls-0.6.0.min.js"></script>
<script type="text/javascript" src="controllers.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css" />
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<title>My App</title>
</head>
<body ng-controller="AppCtrl" style="padding-bottom: 70px">
Bootstrap alone is loaded fine.
What am I doing wrong?
Here is the plnkr
I got a different error with your code. I got a missing $routeProvider error.
As the first line of your app.js try this:
var MyApp = angular.module("MyApp", ["ngRoute", "ngAnimate", "ui.bootstrap"])
instead of
var MyApp = angular.module("MyApp", ["ngAnimate", "ui.bootstrap"])
And add it your header:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular-route.js"></script>
By the way, using the non-minified version of Angular in plnkr.co gives a more human readable error message in these cases.
You are declaring app.js before the angular-animate library. Try this:
<html lang="en" ng-app="MyApp">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="angular-animate.js"></script>
<script type="text/javascript" src="ui-bootstrap-tpls-0.6.0.min.js"></script>
<script type="text/javascript" src="app.js"></script>
<script type="text/javascript" src="controllers.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css" />
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<title>My App</title>
</head>
<body ng-controller="AppCtrl" style="padding-bottom: 70px">

Resources