如何编写包含对象作为输入和控制器独立的角度自定义指令? [英] How can I write a angular custom directive which contain object as a input and controller independent?

查看:78
本文介绍了如何编写包含对象作为输入和控制器独立的角度自定义指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自一个控制器的数据我想在另一个控制器中使用它我希望指令控制器独立。当我使用我在用户中定义的控制器时,它正在工作



我尝试了什么:



指令 -

angular.module('app')。指令('userInfoCard',function(){

return {< br $>


限制:E,

范围:{

用户:'='

},

控制器:mainCtrl,

templateUrl:../../templates/list.html



}

});

HTMl-

the data which is coming from one controller I want to use it in another one I want directive controller independent. it is working when I am using controller in which I defined in user is defied

What I have tried:

Directive-
angular.module('app').directive('userInfoCard', function() {
return {

restrict: "E",
scope: {
user: '='
},
controller:"mainCtrl",
templateUrl: "../../templates/list.html"

}
});
HTMl-



< user-info-card user =Events>


<user-info-card user="Events">





主控制器 -



有角度。模块('app')。控制器('mainCtrl1',['$ scope','$ http',



函数($ scope,$ http){

$ http.get('../../ js / flask / data.json')。成功(函数(数据){

调试器;

$ scope.Events = data.Events;





});

}] );



Main-Controller-

angular.module('app').controller('mainCtrl1',['$scope', '$http',

function($scope,$http) {
$http.get('../../js/flask/data.json').success(function(data) {
debugger;
$scope.Events = data.Events;


});
}]);

推荐答案

scope','


http',



函数(
http',

function(


scope,


这篇关于如何编写包含对象作为输入和控制器独立的角度自定义指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆