html
<p on-test data={{userinfo}}></p>
//自定义指令on-test,contorller中通过ajax的方式从后台拿到userinfo,userinfo是一段很长的json字符串,会随着用户的操作而变化
directive
app.directive('onTest', function () {
return {
restrict: 'A',
scope:{
test:'@data'
},
link: function(scope , element, attr) {
console.log(scope)
/**
*我想在这里拿到后台传过来的userinfo字符串,通过userinfo操作我的dom界面
**/
}
};
});
My doubts:
I print the scope in the link and can see the passed data, but I cannot get my data through scope.test
Comrade, your gameplay is wrong:
First is the template part. Since you want to monitor the changes of
userInfo
, it is most suitable to use two-way binding, but what you write is binding attributes (this is not cool enough):The following is the command registration part: