If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


  • 0
    ramstein74  10 years ago

    I´m want to export a variable from my web2py controller to my controller.js and for example using your first suggestion and trying a ng-repeat with the array[1,2,3]

    in my web2py controller if i do

    x=[1,2,3]

    return dict(x=x)

     

    then in my controller.js i cannot access my x variable.

    $scope.cods= "<?=cods?>";

    i get this error

     

    Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: x in cods|filter:search, Duplicate key: string:?

    However if i embed my controller.js code in my web2py view it works

     

    Why?

    replies (1)
    • rppowell 10 years ago

      I am assuming that the controller.js is originally under /static/controllers.js.

      URLs to the static files do not get called through the framework and are simply returning the unprocessed file in the /static folder; thus, no value is substituted for the variable placeholder in the returned javascript for controller.js file request.

      When a request is made to the web2py framework via HTTP call (POST/GET), it is using a URL; the URL is processed and, after going through the application/controller path, is calling the specified controller's function. If there is a corresponding view, then the contents are used as a template to generate data that is returned.

      If the call is to 'static', then the URL file location is returned, no template processing of the file contents is done.

      See AngularJS-templates at https://groups.google.com/d/topic/angular2py-dev/7BInWrxk-ho/discussion with details at: https://groups.google.com/d/msg/angular2py-dev/7BInWrxk-ho/7IL2Ffij0psJ

Commented on:

Some examples on getting started with angular.js and dealing with the handlebars delimiters.

Hosting graciously provided by:
Python Anywhere