Sam*_*mal 8 angularjs angularjs-directive angularjs-scope
如何将自定义字段添加到角度范围以及将传递的字段作为属性添加,如下所示:
angular.module('app')
.directive("myDirective", function(){
function NewObj()
{
this.id = 0;
this.name = "";
}
return{
restrict: "E",
templateUrl:"partials/directives/temp.html",
scope:{
viewId:"=",
dataObj: new NewObj() //This is the custom obj
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到无效的隔离范围定义.如何实现这一目标?
指令中的范围只能是'=','&','@'中的一个.要做你想做的事,你可以尝试这样的事情:
angular.module('app')
.directive("myDirective", function() {
function NewObj() {
id = 0;
this.name = "";
}
return {
restrict: "E",
templateUrl:"partials/directives/temp.html",
scope: {
viewId:"=",
},
controller: ['$scope', function($scope) {
$scope.dataObj = new NewObj();
}]
};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5094 次 |
| 最近记录: |