AngularJs custom directive isolated scope custom fields
angularjs, angularjs-directive, angularjs-scope
Solution
The scope in a directive can only be one of '=', '&', '@'. To do what you want, you can try something like:
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();
}]
};
});
Problem
How can I add custom fields to angular scope along with passed fields as attributes, as the following: ``` 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 } } } ``` When I do so, I get invalid isolated scope definition. How can this be accomplised ?