我正在创建项目,使用angularjs.I创建自定义指令时出现问题。其实我想从控制器发送值到指令,但我得到了未定义。这里是我的代码:从控制器传递值到指令
下面是指令
.directive('angularData', function ($parse) {
return {
template: false,
scope: {
chart: '=lineChartData'
},
restrict: 'EA',
replace: true,
link: function postLink(scope, element,attrs) {
var canvas, context, chart, options;
console.log(attrs)
console.log(scope.chart) //undefiend
console.log(chart) //undefiend
}
};
});
这里的Html,我所说的指令
<canvas id="test" angular-data ="lineChartData" height="450" width="600"></canvas>
这里是控制器代码
$scope.lineChartData = {
labels :[1,4,8,6,8],
datasets : [
{
label: "My First dataset",
fillColor : "rgba(220,220,220,0.2)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : [1,4,8,6,8]
}
]
}
这也不适用 – angular