AngularJS/Javascript 下拉菜单 "onchange" 功能无效
AngularJS/Javascript dropdown "onchange" function is not working
<select name="Connection" class="mdl-button" id="dropConnection" onchange="connectionChange()" ></select>
内容是从 JSON response.Thats 自动添加的,工作正常。
function connectionChange()
{
var sel = document.getElementById("dropConnection");
var connectionName = sel.options[sel.selectedIndex].text;
$scope.connectionDetail = response.data.message.connectionDetailses.filter(det => det.connectionId === connectionName);
console.log($scope.connectionDetail);
}
在 运行 页面之后,当我更改下拉内容时显示错误
home.html:265 Uncaught ReferenceError: $scope is not defined
at connectionChange (home.html:265) // above javascript code.
at HTMLSelectElement.onchange (VM4122 home.html:139)
home.html:265 Uncaught ReferenceError: $scope is not defined
at connectionChange (home.html:265) // above javascript code.
at HTMLSelectElement.onchange (VM4122 home.html:139)
查看此错误可以推断您没有在控制器中注入 $scope
。在您的控制器中注入 $scope
,它将解决此错误。
查看 link 了解如何在 AngularJS 中正确创建控制器 AngularJS controller
<select name="Connection" class="mdl-button" id="dropConnection" onchange="connectionChange()" ></select>
内容是从 JSON response.Thats 自动添加的,工作正常。
function connectionChange()
{
var sel = document.getElementById("dropConnection");
var connectionName = sel.options[sel.selectedIndex].text;
$scope.connectionDetail = response.data.message.connectionDetailses.filter(det => det.connectionId === connectionName);
console.log($scope.connectionDetail);
}
在 运行 页面之后,当我更改下拉内容时显示错误
home.html:265 Uncaught ReferenceError: $scope is not defined
at connectionChange (home.html:265) // above javascript code.
at HTMLSelectElement.onchange (VM4122 home.html:139)
home.html:265 Uncaught ReferenceError: $scope is not defined
at connectionChange (home.html:265) // above javascript code.
at HTMLSelectElement.onchange (VM4122 home.html:139)
查看此错误可以推断您没有在控制器中注入 $scope
。在您的控制器中注入 $scope
,它将解决此错误。
查看 link 了解如何在 AngularJS 中正确创建控制器 AngularJS controller