我的指示导致学校下降
function campuses(){
return{
restrict: "AE",
scope:{
display: "@",
optGroup: "@",
orderBy: "@",
showGrades: "@",
dirClass: "@",
campusCls: "@",
gradeCls: "@"
},
transclude: true,
templateUrl: "XXXX/XXXXX/campus-dropdown/campus-template.html",
controller: campusCtrl,
link: campusLink
}
}
模板网址
加载的HTML文件<div class="form-group {{campusCls}}">
<select
id="campus-dropdown"
class="form-control"
ng-model="campusModel"
ng-options="item.campusNum as item.campusLabel {{customGroupBy}} for item in campusList {{customOrderBy}} track by item.campusNum"
title="{{display}} campuses">
<option value="">Select all Campuses</option>
</select>
我遇到的主要问题是将ID校园纳入我的指令。 每次我尝试document.getelementbyid或$(&#39;#campus-dropdown&#39;)我只会获得空值
我尝试在控制器和我的链接中访问此变量,但仍然没有运气
答案 0 :(得分:1)
您正在使用此命令在指令中创建隔离范围:
scope:{ display: "@", optGroup: "@", ...}
工作plunk
您需要创建/使用名为scope之外的自定义属性。
在你的控制器中:
$scope.foo = {
display: "",
optGroup: "",
orderBy: "",
showGrades: "",
dirClass: "",
campusCls: "",
gradeCls: ""
}
HTML:
<campus-dir foo="{{foo}}"></campus-dir>
指令:
foo: "@"