javascript - 如何将范围值传递给指令 Controller

标签 javascript angularjs

我正在尝试将范围值数组从 Controller 传递到指令,这如何可能。

我需要将此值传递给我的指令 Controller $scope.recipientsOrgIdArr.push(data.latedEntityInstanceId);

HTML 文件

<search  searchobj="tei_org"  selecteditemslist="recipientsOrgIdArr"   searchid="organisation" />

搜索指令

.directive('search', function ($timeout) {
    return {
        restrict: 'AEC',
        scope: {
            selecteditemslist: "="
}
link: function (scope, elem, attrs) {
console.log(scope.selecteditemslist);  // getting as undefined

//how can i get scope value here
}
}
})

请帮我解决这个问题,提前致谢

最佳答案

您遇到的问题是,在调用指令链接函数时,selecteditemslist 尚未设置。

试试这个

.directive('search', function ($timeout) {
    return {
        restrict: 'AEC',
        scope: {
            selecteditemslist: "="
        }
        link: function (scope, elem, attrs) {
            scope.$watch('selecteditemslist', function(value) {
                if(value){
                    console.log(scope.selecteditemslist);
                }
        }...

关于javascript - 如何将范围值传递给指令 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161585/

相关文章:

javascript - 作为 WordPress 管理员,如何更改用户的个人资料照片?

javascript - 添加html后使用php打开页面

javascript - 捕获所有不在集合中的点击

javascript - AngularJS - 子指令使用与父指令相同的数据。如何分享?

javascript - 在 Angular 指令中将函数作为参数传递不起作用

javascript - 使用 angularjs 或 javascript 的 flask reSTLess 批量删除,这可能吗?

angularjs将属性中新创建的数组传递给指令

javascript - Google Maps Javascript API 给出 ​​INVALID_REQUEST

javascript - Mesh.setGeometry 可以使用 Famo.us Engine 传递图像吗

javascript - AngularJS 中的 Promise