I have 8 jade
view that only one of them is loaded at the time and is filled by jquery
into a div
which has a controller
.
Now, I have 2 question about these:
- Does it necessary to define again the
controller
on top of my partial view(samecontroller
with maincontroller
) ? - All of these views has same
ng-click
. but after loading they doesn't work. However they work by jquery click event. Should I do any extra thing with them?
I had same problem with li
element before, but I resolve it by getting help from ng-click not working from dynamically generated HTML by using compileData but I can't get result with button.
Code:
Main jade:
div(ng-controller="elementCtrl")
div#ddd(class="col-lg-7 col-md-5 col-sm-7")
Partial view sample:
div#spPartial()
div.col-lg-12.col-md-12.col-sm-12
span.col-lg-2.col-md-5.col-sm-5 Name
input#EnglishName(name="name" type="text" ng-model="elementModel.Name" value="#{Name}" class="col-lg-5 col-md-7 col-sm-5")
button(type="button" compile-Data name="btnSaveElement" ng-click="saveElement()") Save
Main part of controller:
//It loads the partial view - It works successfully
$http.post('/api/elements/getElementTypesPartial',
{
"ElementId": elementId,
"ProgramId": newVal,
"ElementTypeId": elementTypeId
})
.success(function (d2) {
$("#ddd").html(d2);
}
//It doesn't work at all
$scope.saveElement = function () {
alert();
alert($scope.elementId);
}
And one additional thing is that I put $scope.saveElement
in root of controller scope. I don't have any idea about how angularJs manage $scope, So I see $scope.elementId
in client code. Is it right or I should regenerate it($scope.saveElement
) every time that partial is loaded?
Sorry I couldn't find any reference which describes these...