我试图在角度函数中运行JavaScript函数,但我面临错误 (曾经索引,搜索功能不起作用)
<select class="form-control input-sm input_high" name="groupname" id="groupname" ng-model="tech_groupname">
<option value="">Select</option>
<option value="Dedicated-1">Test1</option>
<option value="Dedicated-2">Test2</option>
<option value="Yellow-2">Test3</option>
</select>
<div class="ui-widget" ng-if="checkCorpPackage(tech_groupname)" ></div>
appTechInfo.controller('tech_info_ctrl', ['$scope',function($scope)
{
//** check if package is corporate and need if start
$scope.checkCorpPackage = function(temp_grp_name){
//value is printed here if javascript function is not used
console.log(temp_grp_name);
//i have tested by getting data via scope too
var test_data = $scope.tech_groupname;
console.log(temp_grp_name.toLowerCase());
/**
if(temp_grp_name.indexof("Dedicated") > -1)
{
return true;
}
else
{
return false;
}
**/
}
//** check if package is corporate and need if start
}]);
错误日志 TypeError:无法读取未定义的属性'toLowerCase'
我已经搜索过类似的问题,但他们提供的解决方案对我不起作用
答案 0 :(得分:2)
temp_grp_name将是未定义的,因为它的值将在更改选择控件时更改。所以你必须通过检查undefined或null来处理它。 indexof 将 indexOf ,如下所示
temp_grp_name.indexOf("Dedicated")