Typeerror: Cannot Read Property 'split' Of Undefined
This is my HTML file. When i am running the HTML page it is showing error,'Cannot read property 'split' of undefined'
Solution 1:
if(text!==undefined){
return text.split('-').join(' ');
}
In my opinion above condition should be replaced with below code
if(text){
return text.split('-').join(' ');
}
This condition checks all i.e defined, not null and not empty string.
Hope this helps.
Solution 2:
You are missing ng
in <input type="text" model="someDashedText">
=> <input type="text" ng-model="someDashedText">
.
Not sure that 'strict not equal' !==
operator is necessary here..., you might just check if anything is there if(text)
Here is working Plunker.
Solution 3:
I have made a small code change and created a separate module for the filter and used in the 'appModule'.
You must use "ng-model" in the input.
Here is the working script.
<!DOCTYPE html><html><head><scriptsrc = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script><script>
angular.module('dash',[]).filter('removeDashes',function(){
returnfunction(text){
if(text!==undefined){
return text.split('-').join(' ');
}
}
});
angular.module('appModule', ['dash']).controller('someCTRL', function($scope){
});
</script></head><bodyng-app="appModule"ng-controller="someCTRL"><inputtype="text"ng-model="someDashedText"><p>
{{someDashedText|removeDashes}}
</p></body></html>
Post a Comment for "Typeerror: Cannot Read Property 'split' Of Undefined"