有棱角的从html调用指令中的函数
Angular. call function in directive from html
我正在尝试生成一个指令。这样我就可以在我的html页面中使用它,就像下面的片段:
<testview></testview>
现在唯一要做的就是渲染一个类似的链接
<a><span ng-onmousedown='onSelected('"creame'",event)'>{{value}}</span></a>
当我单击span时,我希望指令通过调用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指令之前,您需要编译模板。
相关文章:
- 从html创建一个指令,该指令按类名应用函数
- AngularJS指令单元测试中未定义的函数
- AngularJS指令部分应用的函数don'不起作用
- 角度指令's链接函数未被调用
- 从子指令调用指令函数不起作用
- 参数未在指令函数中传递
- 如何从 JavaScript 调用指令函数
- Angular.js调用控制器中的指令函数
- 将事件发送到范围中的角度指令函数
- 从父指令角度调用指令函数
- 在具有不同控制器的视图中使用ng-click和指令函数
- 通过参数将 mongo 文档 ID 传递给角度指令函数会抛出解析错误
- Angular指令——函数执行的正确顺序
- 又一个没有传递参数的Angular指令函数
- 如何使子链接指令函数在父控制器之前运行
- AngularJS中指令函数的执行顺序
- 在没有应用指令函数的指令内部重复
- 使用$scope.$parent.$$childHead从控制器访问指令函数.AngularJS中的functionNa
- angularjs设计.从另一个控制器调用指令函数
- 调用angularjs指令函数的范围问题