TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kamila
NA
10
0
Type Error:Cannot read property of Unit undefined
Jun 26 2018 4:38 AM
Hi have added a new text box under the render which is Units and it works fine in local machine but throws error in server built . Does it has to be mounted with the component . Am new to reactjs could some one suggest .
import
React from
'react'
;
class
TextboxInputView
extends
React.Component {
constructor(props) {
super
(props);
this
.state = {
value:
''
}
}
onValueChanged(e) {
var
newValue = e.target.value;
this
.setState({ value: newValue });
if
(
this
.props.valueChanged !=
null
)
this
.props.valueChanged(newValue);
}
render() {
var
unitsCheck =
""
;
if
(
this
.props.data.Unit !=
""
) { unitsCheck = <input id=
"Units"
className=
'col-md-4'
Style=
'font-weight:normal'
readOnly type=
"text"
value={
this
.props.data.Unit} /> }
return
<div key={
this
.props.Id}>
<label>
<input type=
"text"
className=
'col-md-6'
value={
this
.state.value} onChange={(e) =>
this
.onValueChanged(e)} /> {
this
.props.Name}
{unitsCheck}
</label>
</div>;
}
getDefaultValue() {
var
defaultValue =
null
;
if
(
this
.props.defaultValues !=
null
&&
this
.props.defaultValues.length === 1 &&
this
.props.defaultValues[0] !==
''
)
defaultValue =
this
.props.defaultValues[0];
return
defaultValue;
}
componentDidMount() {
var
defaultValue =
this
.getDefaultValue();
if
(defaultValue !=
null
&&
this
.state.value !== defaultValue) {
this
.onValueChanged({ target: { value: defaultValue } });
}
}
componentWillReceiveProps(nextProps) {
if
(
this
.props !== nextProps && nextProps.isResetValues) {
let defaultValue =
this
.getDefaultValue();
defaultValue = defaultValue ===
null
?
''
: defaultValue;
if
(
this
.state.value !== defaultValue) {
this
.onValueChanged({ target: { value: defaultValue } });
}
}
}
}
export
default
TextboxInputView
Reply
Answers (
1
)
How can i work offline on angular 2, 4 project
i need any example for Angular 4, remember me function