How to define a variable in Oracle Service Bus? - osb

How can I define a variable in a proxy service and what is the scope of a variable?

You use an Assign action in the Pipeline.
The scope of that variable is for the PipelinePairNode (Request, Response, and Route).

Use "Assign" from "message processing" design palette. In the properties of "Assign", give any name to that variable in the "variable" property and in "expression" property give the expression of where it would reside..suppose i create a variable named x in body, then in expression i'll give $body.
Scope: Scope of this Assign resource is within the pipeline pair in which it is defined.

Related

How do I know what controller an HTML element belongs to, just by looking at the output (the elements panel in dev tools)?

If I look at an HTML element in a complex angularJS application, and it has basic directive that evaluates an expression, e.g.
<li ng-class="{active: active}"></li>
How can I tell what controller the 'active' property belongs to, just by looking at the markup?
In this case, the active variable doesn't belong to a controller, it belongs to a scope. Scopes use prototype inheritance, so the variable could belong to any scope.
There are multiple directives that create scopes, so it might be hard to realize which scope it belongs to.
If you want to use a controller property, define an alias like ng-controller"myCtrl as alias" (should be unique), then, you can use the propertyas alias.myProperty and the alias will let you know inmediately which controller it belongs to.
In Chrome Developer Console you can grap the element using angular.element($0) method and some useful methods are
Controller : angular.element($0).controller()
Scope : angular.element($0).scope()
Chorme Extension : AngularJS Batarang https://chrome.google.com/webstore/detail/angularjs-batarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en

custom directive parameters declaration differences

I am wondering about the differences between declaring custom directive parameters in these three ways :
js :
app.directive('customDirective', function() {
return {
restrict: 'E',
scope : {
x : '=',
y : '=y',
z : '=?'
} ,
}
});
I am monitoring the three seems same behavior.
Can anyone help ?
The first is the usual two-way data-binding, which means if you say x : '=' the attribute on the element has to be x as well.
The second is an alternative to the first one with the difference that you can map the scope variable to a different attribute. For example you could say y: '=foo'. This maps the attribute foo to y.
With the last one you specify optional attributes, so you don't have to pass them along (not required).
For more information check the AngularJS documentation on $compile here.
TL;DR
= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value
of the attr attribute. If no attr name is specified then the attribute
name is assumed to be the same as the local name. Given and widget definition of scope: {
localModel:'=myAttr' }, then widget scope property localModel will
reflect the value of parentModel on the parent scope. Any changes to
parentModel will be reflected in localModel and any changes in
localModel will reflect in parentModel. If the parent scope property
doesn't exist, it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION
exception. You can avoid this behavior using =? or =?attr in order to
flag the property as optional. If you want to shallow watch for
changes (i.e. $watchCollection instead of $watch) you can use =* or
=attr (=? or =*?attr if the property is optional).
Edit: I think the documentation is outdated because the exception appears to be thrown only in older revisions of the $compile source. In newer versions of AngularJS required scope properties which do not exist will be undefined.
Edit 2: As I have mentioned before that a newer version of Angular won't throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception anymore you will still get an error whenever you try to assign a value to an optional property which is not defined on the element.
= and =y are the same.
You can define different scope and html-attribute names like
scope:{
a: '=b'
}
With this you would bind the html-attribute bto the scope value a
=? is an optional binding. So the attribute isnt required

In AngularJS is $scope actually the parent object's body?

In AngularJS is $scope actually the parent object's body? If so, does this mean that the controller in the image below (called "MainCtrl") is essentially setting two variables within the MODULE and that "categories" and "bookmarks" would now be available within the module called "Eggly?"
OR...
Is the function, passed in as the 2nd argument of the controller function actually NEWING UP a new empty object and passing that new object in as the $scope? That would indicate that the two variables are being set on the new object and the new object, with the new variables, would be set as the controller.
From a C# perspective
In C# it is common to pass in "this" when creating an instance of an object within an object IF the child needs to access the parent. The child would receive this and have access to any PUBLIC properties or methods. It appears that passing in $scope does something similar except that EVERYTHING in the parent is available from the child (probably a function).
Setting a property on $scope exposes the property to whoever sees this scope, typically child directives and controllers.
It doesn't set it "on the module" - whatever that means.

directive scope two way binding not working using "="

i have this very simple directive.
you can find the code here
In the code,
i have used '#' for link in the scope.
I am able to get it correctly.
But this is not two way binding, so i tried to do it with "=" in scope.
This part does not seems to reflect in my template. I tried to do see if the link variable
is present in scope,it seems to be undefined.
Should this directive be placed inside a controller?
What is that i am missing in my code.
You seem to be missing the difference between the # and = bindings. While the 2 might look similar those are fundamentally different ways of bridging "directive world" with the "page world".
Firstly, let's start with the similarities: both types of binding allows you to pass data from a page that is using a directive to the directive itself (directive intenal scope). But this is where similarities end, and the list of differences goes like this:
= is the 2-way data binding that can cross page / directive world in both ways: from a page to a directive and from the directive scope to the page scope. # on the other hand only allows you to pass data from a page to the directive and not from the directive to the page.
= binding allows you pass data defined on scopes - that is - any JavaScript variable (primitives, arrays, objects). # is different and is passing data through a DOM attribute. As such those attributes are restricted to Strings only.
given the above, the = and # are also triggered differently from the page that is using a directive: for = we need to pass an expression that points to data defined on the scope
while with # we are going through the DOM and need to use the interpolation directive ({{foo}}) to access data available on the scope.
After all those explanations you can see that using = in the directive definition we need to pass an expression so if you do this: <mydirective link="link1" group="main"></mydirective> you are effectively saying: pass to the directive a value of the link1 variable defined on a scope. Since such variable is not defined you are passing undefined to the directive.
So, if you intend to pass a constant (which I assume you want to do), you will need to write:
<mydirective link="'link1'" group="main"></mydirective>
Here is a working plunk: http://plnkr.co/edit/M3qL4MdmoWjTWzZGkwz0?p=preview
One thing most people forget is that you can't just declare an isolated scope with the object notation and expect parent scope properties to be bound. These bindings only work if attributes have been declared through which the binding 'magic' works. See for more information:
https://umur.io/angularjs-directives-using-isolated-scope-with-attributes/

AngularJS Documentation on Isolate Scope Attributes

Is there any AngularJS documentation providing a straightforward definitive list of ways to handle attributes in a directive with isolate scope?
The directive guide touches upon the use of = but doesn't list the other options used for binding.
So far, I'm aware of (via mixed sources):
scope: {
myAttr1: '=attr1',
myAttr2: '=?attr2',
myAttr3: '#attr3',
myAttr4: '&attr4'
},
have a look at the compile service: http://docs.angularjs.org/api/ng.$compile
The 'isolate' scope takes an object hash which defines a set of local scope properties derived from the parent scope. These local properties are useful for aliasing values for templates. Locals definition is a hash of local scope property to its source:
# or #attr - bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localName:'#myAttr' }, then widget scope property localName will reflect the interpolated value of hello {{name}}. As the name attribute changes so will the localName property on the widget scope. The name is read from the parent scope (not component scope).
= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localModel:'=myAttr' }, then widget scope property localModel will reflect the value of parentModel on the parent scope. Any changes to parentModel will be reflected in localModel and any changes in localModel will reflect in parentModel. If the parent scope property doesn't exist, it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception. You can avoid this behavior using =? or =?attr in order to flag the property as optional.
& or &attr - provides a way to execute an expression in the context of the parent scope. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localFn:'&myAttr' }, then isolate scope property localFn will point to a function wrapper for the count = count + value expression. Often it's desirable to pass data from the isolated scope via an expression and to the parent scope, this can be done by passing a map of local variable names and values into the expression wrapper fn. For example, if the expression is increment(amount) then we can specify the amount value by calling the localFn as localFn({amount: 22}).
You can also look at the older documentation of directive. I believe the new one is better to understand but the older one has more meat.
http://code.angularjs.org/1.1.5/docs/guide/directive

Resources