[英]Angular. call function in directive from html
我正在嘗試發出指令。 這樣我就可以在我的html頁面中使用它,如下所示:
<testview></testview>
現在唯一要做的就是渲染一個像
<a><span ng-onmousedown='onSelected(\"creame\",event)'>{{value}}</span></a>
當我單擊范圍時,我希望指令通過調用onSelected函數來更改$ scope.value。 但是我不能這樣稱呼。
完整代碼示例
function testView() {
$scope.value =
{
name: "dummy"
}
testHtml += "<a><span ng-onmousedown='onSelected(\"creame\",event)' >" + $scope.value.name + "</span></a>";
return {
restrict: 'AE',
replace: 'true',
template: testHtml,
};
}
app.directive('testview', testView);
function onSelected(input)
{
$scope.value.name = input;
}
有誰知道我該怎么做? 謝謝你的時間
嘗試這個
function testView() {
testHtml += "<a><span ng-onmousedown='onSelected(\"creame\")' >{{value.name }}</span></a>";
return {
restrict: 'AE',
replace: 'true',
template: testHtml,
};
}
app.directive('testview', testView);
app.controller('CampaignsOverviewController', Controller);
function Controller ($scope) {
$scope.onSelected = onSelected;
$scope.value =
{
name: "dummy"
}
function onSelected(input)
{
$scope.value.name = input;
}
}
我認為您需要先編譯模板,然后才能執行ngOnMouseDown指令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.